<style>
    .import {
        opacity: 0;
        position: absolute;
        width: 69px;
        height: 38px;
        margin-left: -10px;
    }

    .width105 {
        width: 105px;
    }

    .borderNone {
        border: none;
        color: red;
    }

    .selectAddPlatformForm label {
        width: 120px;
        padding: 9px 5px;
    }

    .layui-table-cell {
        height: auto;
    }

    .inputBorderNone {
        border: none;
        background: transparent;
        outline: none;
    }

    .addSelfCollectedGoodsForm label {
        width: 100px;
    }

    div[lay-id="addSelfCollectedGoodsTable"] .layui-table-cell,
    div[lay-id="addSelfCollectedGoodsTable"] .layui-form,
    div[lay-id="addSelfCollectedGoodsTable"] .layui-table-box,
    div[lay-id="addSelfCollectedGoodsTable"] .layui-table-body,
    div[lay-id="addSelfCollectedGoodsTableModifyList"] .layui-form,
    div[lay-id="addSelfCollectedGoodsTableModifyList"] .layui-table-box,
    div[lay-id="addSelfCollectedGoodsTableModifyList"] .layui-table-body,
    div[lay-id="addSelfCollectedGoodsTableList"] .layui-table-cell {
        overflow: visible;
        padding: 0 0;
    }

    div[lay-id="addSelfCollectedGoodsTableModifyList"] .layui-table-cell {
        overflow: visible;
        padding: 0 5px;
    }

    #productPic_path > img {
        max-height: 350px;
        max-width: 700px;
    }

    form[lay-filter="compactProductForm"] .layui-form-label {
        padding: 9px 10px;
        width: 110px;
    }
    [lay-filter="compactProductForm"] input[disabled]{
        background-color: #D2D2D2;
        cursor:not-allowed ;
    }

    .inputTips {
        display: inline-block;
        line-height: 38px;
        width: 40px;
        color: #666;
    }

    div[lay-id='commonToolCabinetTable'] .layui-table-body .layui-table-cell{
        height: 79px;
        line-height: 79px;
    }
    .layui-form-mid {
        float: left;
        display: block;
        padding: 7px 0!important;
        line-height: 20px;
        margin-right: 10px;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料名称：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" placeholder="物料名称" name="skuName" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料编号：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" placeholder="物料编号" name="skuCode" autocomplete="off">
                                    </div>
                                </div>
                                <!--                                <div class="layui-inline">-->
                                <!--                                    <label class="layui-form-label w-auto">原物料编号：</label>-->
                                <!--                                    <div class="layui-input-inline">-->
                                <!--                                        <input type="text" class="layui-input" placeholder="原物料编号" name="oldSkuCode">-->
                                <!--                                    </div>-->
                                <!--                                </div>-->
                                <div class="layui-inline">
                                    <label class="layui-form-label">规格码：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" placeholder="规格码"
                                               name="oldSpecCode" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">品牌：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" placeholder="品牌"
                                               name="productBrandName" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">创建时间：</label>
                                    <div class="layui-input-inline">
                                        <input name="createTime" id="pTime" class="layui-input" type="text"
                                               placeholder="选择时间" autocomplete="off" readonly/>
                                    </div>
                                    <input name="startTime" id="startTime" type="hidden"/>
                                    <input name="endTime" id="endTime" type="hidden"/>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">系列名称：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" placeholder="系列名称" name="productName" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料类型：</label>
                                    <div class="layui-input-inline">
                                        <select name="productTypeId" lay-search="" class="common-select-search"></select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料分类：</label>
                                    <div class="layui-input-inline">
                                        <input type="hidden" name="productCategoryId">
                                        <div id="productCategoryIdXmSelect"></div>
                                    </div>
                                </div>
                            </div>

                            <div class="query-rt">
                                <button id="propsBagSearch" class="layui-btn icon-btn" type="button" lay-filter="formSubSearchLog"
                                        lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询
                                </button>
                                <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <!--<button id="fromPlatformAddBtn" class="layui-btn icon-btn" type="button"
                                    lay-filter="fromPlatformAddBtn">
                                从平台添加
                            </button>-->
                            <!--新 从平台添加 -->
                            <!--<a id="addPlatformBtn" class="layui-btn color-green" type="button"lay-filter="addPlatformBtn">
                                从平台添加
                            </a>-->
                            <!--<button id="batchDelTool" class="layui-btn icon-btn layui-btn-danger" type="button"
                                    lay-filter="batchDelTool">
                                批量删除
                            </button>-->
                            <!--<button id="fromOneselfPickAddBtn" class="layui-btn icon-btn" type="button"
                                    lay-filter="fromOneselfPickAddBtn">
                                添加自采物料
                            </button>-->
                            <!--<button id="fromLocalWarehouseAddBtn" class="layui-btn icon-btn" type="button"
                                    lay-filter="fromLocalWarehouseAddBtn">
                                从本地添加
                            </button>-->


                            <!--  <button id="addSelfCollectedGoodsBtn" class="layui-btn icon-btn color-green"
                                      lay-filter="addSelfCollectedGoodsBtn">新添加自采物料
                              </button>-->

                            <button id="addProductBtn" class="layui-btn icon-btn color-reseda" type="button"
                                    lay-filter="addProductBtn">
                                添加物料
                            </button>
                            <button class="layui-btn icon-btn color-reseda"><input
                                    id="compactUploaderInput" type="file" name="file" class="import"
                                    accept=".xls,.xlsx"/>导入物料
                            </button>
                        </div>
                        <div class="lay-btn-rt">
                            <!-- <button id="fromLocalWarehouseBtnImport" class="layui-btn icon-btn color-green"><input
                                     id="uploaderInput" type="file" name="file" class="import" accept=".xls,.xlsx"/>导入
                             </button>-->

                            <button id="exportProductBtn" class="layui-btn icon-btn color-green">导出</button>
                            <!--<button id="fromLocalWarehouseBtnTemplate" class="layui-btn icon-btn color-green">模板下载
                            </button>-->
                            <button id="compactProductBtnTemplate" class="layui-btn icon-btn color-green">物料模板下载
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="commonToolCabinetTable" lay-filter="commonToolCabinetTable"></table>
        </div>
    </div>
</div>


<!-- 列表操作 -->
<script type="text/html" id="commonToolCabinetTableBar">
    <a class="layui-btn  layui-btn-xs" lay-event="detailsTableBarBtn">详情</a>
    <a class="layui-btn  layui-btn-xs layui layui-btn-danger" lay-event="cancellationTableBarBtn">作废</a>
    <a class="layui-btn  layui-btn-xs" lay-event="modifyTableBarBtn">修改</a>
    <a class="layui-btn  layui-btn-xs" lay-event="storageBtn">入库</a>
    <a class="layui-btn  layui-btn-xs" lay-event="outboundBtn">出库</a>
    <!--<a class="layui-btn  layui-btn-xs" lay-event="warningBtn">安全库存设置</a>-->
    <!-- <a class="layui-btn  layui-btn-xs" lay-event="storageDetailsBtn">入库详情</a>
    <a class="layui-btn  layui-btn-xs" lay-event="skuListTableBarBtn">物料</a> -->
    <!--<a class="layui-btn  layui-btn-xs layui-btn-danger" lay-event="del">删除</a>-->
</script>

<!-- 详情弹窗 -->
<script type="text/html" id="listDetails">
    <form lay-filter="listDetailsForm" class="layui-form" style="padding-top: 10px;">
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>规格系列</label>
                <div class="layui-input-inline">
                    <input type="text" name="productName" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>物料名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="skuName" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>物料编号</label>
                <div class="layui-input-inline">
                    <input type="text" name="skuCode" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-row">
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>规格码</label>
                <div class="layui-input-inline">
                    <input type="text" name="oldSpecCode" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>品牌</label>
                <div class="layui-input-inline">
                    <input type="text" name="productBrandName" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>所属分类</label>
                <div class="layui-input-inline">
                    <input type="text" name="productCategoryName" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>物料类型</label>
                <div class="layui-input-inline">
                    <input type="text" name="productTypeName" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>市场价</label>
                <div class="layui-input-inline">
                    <input type="text" name="marketPrice" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>单位</label>
                <div class="layui-input-inline">
                    <input type="text" name="unitName" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>库存数</label>
                <div class="layui-input-inline">
                    <input type="text" name="quantity" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>在柜库存</label>
                <div class="layui-input-inline">
                    <input type="text" name="quantityCab" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>采购预警</label>
                <div class="layui-input-inline">
                    <input type="text" name="warningQuantity" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="margin-bottom: 0;">
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>归还时长阈值</label>
                <div class="layui-input-inline">
                    <input type="text" name="returnThreshold" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>呆滞时长阈值</label>
                <div class="layui-input-inline">
                    <input type="text" name="lethargyThreshold" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
            <div class="layui-col-md4">
                <label class="layui-form-label width105"><span style="color: red">*</span>描述</label>
                <div class="layui-input-inline " style="line-height: 37px;">
                    <input type="text" name="description" lay-verify="" class="layui-input borderNone" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="box-sizing: border-box; padding: 0 20px">
            <table class="layui-table" id="listDetailsFormTable" lay-filter="listDetailsFormTable"></table>
        </div>
    </form>

</script>


<!-- 新 从平台添加弹窗 -->
<!-- addPlatform -->
<script type="text/html" id="addPlatform">
    <form lay-filter="addPlatformForm" class="layui-form model-form addPlatform"
          style="padding: 20px 15px 0 15px;height: calc(100% - 20px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px);">
            <div class="layui-form-item">
                <label class="layui-form-label">平台参数：</label>
                <div class="layui-inline">
                    <!--物料类型-->
                    <select name="productTypeId" lay-filter="productTypeId"></select>
                </div>
                <div class="layui-inline">
                    <select name="productCategoryId" lay-filter="productCategoryId">
                        <!--物料类型-->
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="productUnitId">
                        <!-- 物料单位-->
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="">
                        <option value="">状态</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="productBrandId">
                        <!-- 品牌-->
                    </select>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn icon-btn" type="button" lay-submit="" lay-filter="addPlatformSearch">搜索</a>
                </div>
            </div>
            <div class="layui-form-item">
                <a id="addPlatformImportBtn" class="layui-btn icon-btn" type="button" style="margin-left: 25px">批量导入</a>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="addPlatformTable" lay-filter="addPlatformTable"></table>
            </div>
        </div>


        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<!-- 新 从平台添加弹窗操作 -->
<!--addPlatformTableBar-->
<script type="text/html" id="addPlatformTableBar">
    <a class="layui-btn  layui-btn-xs" lay-event="addPlatformTableDetailsBtn">详情</a>
</script>
<!-- 新 从平台添加弹窗选中的数据-->
<!--selectAddPlatform-->
<script type="text/html" id="selectAddPlatform">
    <form lay-filter="selectAddPlatformForm" class="layui-form model-form selectAddPlatformForm"
          style="padding: 20px 30px 0;height: calc(100% - 20px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px);">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">所属平台类型：</label>
                    <div class="layui-input-inline">
                        <input name="productTypeName" class="layui-input" type="text" disabled/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">所属平台分类：</label>
                    <div class="layui-input-inline">
                        <input name="productCategoryName" class="layui-input" type="text" disabled/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">本地物料类型：</label>
                    <div class="layui-input-inline">
                        <select name="productTypeId" lay-verify="required"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">本地物料分类：</label>
                    <div class="layui-input-inline">
                        <input name="localProductCategoryId" type="hidden" lay-verify="required">
                        <div class="layui-input-inline" id="localProductCategoryId"></div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">本地品牌：</label>
                    <div class="layui-input-inline">
                        <select name="brandId" lay-verify="required"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">本地基础单位：</label>
                    <div class="layui-input-inline">
                        <select name="unitId" lay-verify="required"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">同步平台规格码：</label>
                    <div class="layui-input-inline">
                        <select name="isSpecificationCode" lay-verify="required">
                            <option value="1">使用平台规格码</option>
                            <option value="0">不使用平台规格码</option>
                        </select>
                    </div>
                </div>
                <!--                <div class="layui-inline">-->
                <!--                    <label class="layui-form-label">添加人：</label>-->
                <!--                    <div class="layui-input-inline">-->
                <!--                        <input name="" class="layui-input" type="text"/>-->
                <!--                    </div>-->
                <!--                </div>-->
                <!--                <div class="layui-inline">-->
                <!--                    <label class="layui-form-label">添加时间：</label>-->
                <!--                    <div class="layui-input-inline">-->
                <!--                        <input name="" class="layui-input" type="text"/>-->
                <!--                    </div>-->
                <!--                </div>-->

            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="selectAddPlatformTable" lay-filter="selectAddPlatformTable"></table>
            </div>
        </div>


        <div class="layui-form-item text-right">
            <button class="layui-btn" type="button" id="selectAddPlatformSubmitBtn"
                    lay-filter="selectAddPlatformSubmitBtn" lay-submit>提交
            </button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>


<!-- 从平台添加弹窗 -->
<!-- fromPlatformAdd -->
<script type="text/html" id="fromPlatformAdd">
    <form lay-filter="fromPlatformAddForm" class="layui-form model-form">
        <div class="layui-card-body">
            <!-- 头部操作 -->
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input name="name" class="layui-input" type="text" placeholder="物料名称" autocomplete="off"/>
                    </div>
                    <div class="layui-inline">
                        <input name="brandName" class="layui-input" type="text" placeholder="品牌" autocomplete="off"/>
                    </div>
                    <div class="layui-inline">
                        <input name="productCode" class="layui-input" type="text" placeholder="规格系列编码" autocomplete="off"/>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn" type="button" lay-submit=""
                                lay-filter="fromPlatformAddSearch">
                            搜索
                        </button>
                        <!-- <button id="" class="layui-btn icon-btn"  type="button">添加</button> -->
                        <button id="addManualImportBtn" class="layui-btn icon-btn" type="button">批量导入</button>
                    </div>
                </div>
            </div>

            <!-- 表格 -->
            <table class="layui-table" id="fromPlatformAddTable" lay-filter="fromPlatformAddTable"></table>
        </div>
    </form>
</script>

<!-- 从平台添加弹窗操作 -->
<script type="text/html" id="fromPlatformAddTableBar">
    <a class="layui-btn  layui-btn-xs" lay-event="detailsTableBarBtn">详情</a>
    <a class="layui-btn  layui-btn-xs" lay-event="skuListTableBarBtn">物料</a>
    <a class="layui-btn  layui-btn-xs" lay-event="manualImportBarBtn">手动导入物料</a>
</script>

<!-- 从平台添加弹窗操作 (详情弹窗) -->
<!-- details -->
<script type="text/html" id="details">
    <form lay-filter="detailsForm" class="layui-form model-form">
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>物料名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" lay-verify="" class="layui-input borderNone" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>物料编号</label>
            <div class="layui-input-inline">
                <input type="text" name="skuCode" lay-verify="" class="layui-input borderNone" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>物料规格编号</label>
            <div class="layui-input-inline">
                <input type="text" name="skuSpecValueNames" lay-verify="" class="layui-input borderNone" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>品牌</label>
            <div class="layui-input-inline">
                <input type="text" value="" name="brandCode" lay-verify="" class="layui-input borderNone" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>所属分类</label>
            <div class="layui-input-inline">
                <input type="text" value="" name="productCategoryName" lay-verify="" class="layui-input borderNone"
                       disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>物料类型</label>
            <div class="layui-input-inline">
                <input type="text" value="" name="productTypeName" lay-verify="" class="layui-input borderNone"
                       disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>单价</label>
            <div class="layui-input-inline">
                <input type="text" value="" name="sp_price" lay-verify="" class="layui-input borderNone" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>单位</label>
            <div class="layui-input-inline">
                <input type="text" value="" name="unitName" lay-verify="" class="layui-input borderNone" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>物料SN编号</label>
            <div class="layui-input-inline">
                <input type="text" value="" name="brandCode" lay-verify="" class="layui-input borderNone" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"><span style="color: red">*</span>描述</label>
            <div class="layui-input-inline " style="line-height: 37px;" id="xq_description">
                <!-- <input type="text" class="layui-input" placeholder="这里是分类描述" value="" autocomplete="off" name="code"> -->
                <!-- <span>这里是分类的描述</span> -->
            </div>
            <!-- <div class="layui-form-mid layui-word-aux">可以是显示商品详情页面，淘宝那样的</div> -->
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105"></label>
            <div class="layui-input-inline ">
                <!-- <button type="button" class="layui-btn">增加</button> -->
            </div>
        </div>
    </form>

</script>

<!-- sku弹窗 -->
<!-- skuList -->
<script type="text/html" id="skuList">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->

                <!-- 表格 -->
                <table class="layui-table" id="skuListTable1" lay-filter="skuListTable1"></table>
                <br>
                <table class="layui-table" id="skuListTable2" lay-filter="skuListTable2"></table>
            </div>
        </div>
    </div>
</script>

<!-- 添加自采商品 -->
<script type="text/html" id="productForm">
    <form lay-filter="productForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">物料名称</label>
            <div class="layui-input-inline">
                <input name="name" class="layui-input" type="text" placeholder="请输入物料名称" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">规格系列编码</label>
            <div class="layui-input-inline">
                <input name="productCode" id="productCode_edit" class="layui-input" type="text"
                       placeholder="请输入规格系列编码" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物料类型</label>
            <div class="layui-input-inline">
                <select lay-filter="productTypeId" id="productTypeId" name="productTypeId" lay-verify="required">
                    <option value="">请选择物料类型</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物料分类</label>
            <input name="productCategoryId" value="" type="hidden">
            <div class="layui-input-inline mr0" id="productCategoryId">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">扩展分类</label>
            <div class="layui-input-inline mr0" id="productCategoryExt">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-block">
                <input name="keyword" placeholder="请输入关键词" type="text" class="layui-input" lay-verify="required"
                       required autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">卖点描述</label>
            <div class="layui-input-block">
                <input name="sellingPointSpec" placeholder="请输入卖点描述" type="text" class="layui-input"
                       lay-verify="required" required autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">计价方式</label>
            <div class="layui-input-inline mr0">
                <select name="pricingMethod">
                    <option value="piece">按件</option>
                    <option value="weight">按重量</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单位</label>
            <div class="layui-input-inline">
                <select lay-filter="unitId" id="unitId" name="unitId" lay-verify="required">
                    <option value="">请选择单位</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌</label>
            <div class="layui-input-inline">
                <select lay-filter="brandId" id="brandId" name="brandId" lay-verify="required">
                    <option value="">请选择品牌</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品属性</label>
            <div class="layui-input-block">
                <div class="layui-input-inline mr0" id="productAttrHtml" name="productAttrHtml">

                </div>
                <div id="productAttrValueHtml" name="productAttrValueHtml">

                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品规格</label>
            <div class="layui-input-block">
                <div class="layui-input-inline mr0" id="productSpecHtml" name="productSpecHtml">

                </div>
                <div id="productSpecValueHtml" name="productSpecValueHtml">

                </div>
                <div id="productSkuHtml" name="productSkuHtml">
                    <table class="layui-table" id="productSkuTable" name="productSkuTable"
                           lay-filter="productSkuTable"></table>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">物料图片</label>
            <div id="btnUpload14" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传图片</div>
            <div id="btnUpload14_path" style="margin-left: 260px;line-height: 40px;"></div>
            <input id="picture" name="picture" type="hidden"/>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品描述</label>
            <div class="layui-input-block">
                <textarea id="description" name="description" placeholder="请输入内容(200字以内)" class="layui-textarea"
                          maxlength="200"></textarea>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 从本地仓库添加弹窗 -->
<!-- fromLocalWarehouseFormAdd -->
<script type="text/html" id="fromLocalWarehouseFormAdd">
    <form lay-filter="fromLocalWarehouseForm" class="layui-form model-form">
        <div class="layui-card-body">
            <!-- 头部操作 -->
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input name="name" class="layui-input" type="text" placeholder="物料名称" autocomplete="off"/>
                    </div>
                    <div class="layui-inline">
                        <input name="brandName" class="layui-input" type="text" placeholder="品牌" autocomplete="off"/>
                    </div>
                    <div class="layui-inline">
                        <input name="productCode" class="layui-input" type="text" placeholder="规格系列编码" autocomplete="off"/>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn" type="button" lay-submit=""
                                lay-filter="fromLocalWarehouseSearch">
                            搜索
                        </button>
                        <!-- <button id="" class="layui-btn icon-btn"  type="button">添加</button> -->
                        <button id="addLocalImportBtn" class="layui-btn icon-btn" type="button">批量导入</button>
                    </div>
                </div>
            </div>

            <!-- 表格 -->
            <table class="layui-table" id="fromLocalWarehouseAddTable" lay-filter="fromLocalWarehouseAddTable"></table>
        </div>
    </form>
</script>

<!-- 从本地仓库添加弹窗操作 -->
<script type="text/html" id="fromLocalWarehouseTableBar">
    <a class="layui-btn  layui-btn-xs" lay-event="detailsTableBarBtn">详情</a>
    <a class="layui-btn  layui-btn-xs" lay-event="skuListTableBarBtn">SKU</a>
    <a class="layui-btn  layui-btn-xs" lay-event="manualImportBarBtn">手动导入物料</a>
</script>

<script type="text/html" id="skuListTwoTableBar">
    {{# if(d.skuStateCode){ }}
    <a class="layui-btn  layui-btn-xs layui-btn-danger" lay-event="remSkuListTableBarBtn">移出物料包</a>
    {{# }else{ }}
    <a class="layui-btn  layui-btn-xs" lay-event="addSkuListTableBarBtn">添加到物料包</a>
    {{# } }}

</script>

<!-- 编辑SKU表格操作列 -->
<script type="text/html" id="skuTableBar">
    <!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">冻结</a>-->
    {{# if(d.isShow==true){  }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="frozen">冻结</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" lay-event="thaw">解冻</a>
    {{# } }}

</script>

<!--新 添加自采商品-->
<!--addSelfCollectedGoods-->
<script type="text/html" id="addSelfCollectedGoods">
    <form lay-filter="addSelfCollectedGoodsForm" class="layui-form model-form addSelfCollectedGoodsForm"
          style="padding: 5px 10px 0;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px);">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">选择类型：</label>
                    <div class="layui-input-inline">
                        <select name="addSelfCollectedGoodsProductTypeId" lay-verify="required"
                                id="addSelfCollectedGoodsProductTypeId"
                                lay-filter="addSelfCollectedGoodsProductTypeId"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">选择分类：</label>
                    <div class="layui-input-inline">
                        <input name="addSelfCollectedGoodsProductCategoryId" type="hidden" lay-verify="required">
                        <div class="layui-input-inline mr0" id="addSelfCollectedGoodsProductCategoryId"></div>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label ">供应商名称：</label>
                    <div class="layui-input-inline">
                        <select name="supplierId"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">所属品牌：</label>
                    <div class="layui-input-inline">
                        <select name="addSelfCollectedGoodsBrandId"
                                id="addSelfCollectedGoodsBrandId" lay-filter="addSelfCollectedGoodsBrandId"></select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">规格系列名称：</label>
                    <div class="layui-input-inline">
                        <input name="name" class="layui-input" type="text" lay-verify="required" autocomplete="off"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label ">规格系列编码(唯一)：</label>
                    <div class="layui-input-inline">
                        <input name="productCode" class="layui-input" type="text" lay-verify="required" autocomplete="off"/>
                    </div>
                </div>

                <div class="layui-inline addSelfCollectedGoodsNumBox">
                    <label class="layui-form-label ">添加规格数：</label>
                    <div class="layui-input-inline">
                        <input id="addSelfCollectedGoodsNum" class="layui-input" type="text" lay-verify="required"
                               onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" autocomplete="off"/>
                    </div>
                </div>

                <div class="layui-inline" id="returnThresholdBox">
                    <label class="layui-form-label">归还时长阈值</label>
                    <div class="layui-input-inline" style="width: 150px">
                        <input name="returnThreshold" class="layui-input" type="text" lay-verify="number" autocomplete="off"/>
                    </div>
                    <div class="inputTips">天</div>

                </div>
                <div class="layui-inline" id="lethargyThresholdBox">
                    <label class="layui-form-label">呆滞时长阈值</label>
                    <div class="layui-input-inline" style="width: 150px">
                        <input name="lethargyThreshold" class="layui-input" lay-verify="number" type="text" autocomplete="off"/>
                    </div>
                    <div class="inputTips">天</div>
                </div>
                <div class="layui-inline" id="inventoryUnitTypeBox">
                    <label class="layui-form-label">计量单位</label>
                    <div class="layui-input-inline">
                        <select name="inventoryUnitType" lay-verify="required">
                            <option value="">柜机库存计量单位</option>
                            <option value="weight">重量</option>
                            <option value="quantity">数量</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline" id="returnTypeBox">
                    <label class="layui-form-label">是否需要归还</label>
                    <div class="layui-input-inline">
                        <select name="returnType" lay-verify="required">
                            <option value="true">是</option>
                            <option value="false">否</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">采购预警</label>
                    <div class="layui-input-inline">
                        <input name="warningQuantity" class="layui-input" type="text" placeholder="采购预警"/>
                    </div>
                </div>
                <!--                <div class="layui-inline" id="storageKnifeTypeBox">-->
                <!--                    <label class="layui-form-label">存刀柜类型</label>-->
                <!--                    <div class="layui-input-inline">-->
                <!--                        <select name="storageKnifeType" lay-verify="required">-->
                <!--                            <option value="storage">存刀柜</option>-->
                <!--                            <option value="scraper">售刀柜</option>-->
                <!--                        </select>-->
                <!--                    </div>-->
                <!--                </div>-->

            </div>
            <div class="layui-form-item addSelfCollectedGoodsPictureBox">
                <label class="layui-form-label ">图片：</label>
                <div class="layui-inline">
                    <div id="addSelfCollectedGoodsPicture_path" class="uploadImgStyle"></div>
                    <div id="addSelfCollectedGoodsPictureBtn" class="layui-btn" style="float: left;">上传图片</div>
                    <input name="addSelfCollectedGoodsPicture" type="hidden" class="layui-input"
                           id="addSelfCollectedGoodsPicture"/>
                </div>
                <div class="layui-inline" style="float:right;">
                    <label class="layui-form-label "></label>
                    <div class="layui-input-inline">
                        <a class="layui-btn" lay-event="addSelfCollectedGoodsQuery"
                           id="addSelfCollectedGoodsQuery">确定</a>
                    </div>
                </div>
            </div>

            <div class="layui-row addSelfCollectedGoodsTableListBox" style="margin-top: 20px">
                <table class="layui-table" id="addSelfCollectedGoodsTableList"
                       lay-filter="addSelfCollectedGoodsTableList"></table>
            </div>

            <div class="layui-row">
                <table class="layui-table" id="addSelfCollectedGoodsTableModifyList"
                       lay-filter="addSelfCollectedGoodsTableModifyList"></table>
                <div class="layui-form-item">
                    <div class="layui-inline addSelfCollectedGoodsTableModifyListUploadImgBox">
                        <div id="addSelfCollectedGoodsTableModifyListUploadImg_path" class="uploadImgStyle"></div>
                        <div lay-event="addSelfCollectedGoodsTableModifyListUploadImgBtn"
                             id="addSelfCollectedGoodsTableModifyListUploadImgBtn" class="layui-btn"
                             style="float: left;">上传物料图片
                        </div>
                        <input name="addSelfCollectedGoodsTableModifyListUploadImg" type="hidden" class="layui-input"
                               lay-verify=""
                               id="addSelfCollectedGoodsTableModifyListUploadImg"/>
                    </div>

                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" type="button" lay-filter="addSelfCollectedGoodsSubmit"
                    id="addSelfCollectedGoodsSubmit" lay-submit>提交
            </button>
        </div>
    </form>
</script>


<!--新 添加自采 选择供应商  addSelfCollectedGoodsSupplierBar-->
<script type="text/html" id="addSelfCollectedGoodsSupplierBar">
    <select name="addSelfCollectedGoodsSupplier" id="addSelfCollectedGoodsSupplier"
            lay-filter="addSelfCollectedGoodsSupplier" disabled>
    </select>
</script>


<!--新 添加自采  addSelfCollectedGoodsTableListBar -->
<script type="text/html" id="addSelfCollectedGoodsTableListBar">
    {{# if(d.isShow==true){  }}
    <a class="layui-btn layui-btn-xs" lay-event="save">保存</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="modify">修改</a>
    {{# } }}
</script>

<!--单独修改图片-->
<!--imgModifyForm-->
<script type="text/html" id="imgModifyForm">
    <form lay-filter="imgModifyForm" class="layui-form model-form"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px);">
            <div class="layui-row table-bor " style="margin-top: 15px;">
                <div class="layui-form-item">
                    <div id="productPic_path" class="uploadImgStyle"></div>
                    <div id="productPicBtn" class="layui-btn" style="float: left;">
                        <i class="layui-icon">&#xe681;</i>上传图片
                    </div>
                    <input name="productPic" type="hidden" class="layui-input" lay-verify="" id="productPic"/>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="imgModifyFormSubmit" lay-submit type="button">保存</button>
        </div>
    </form>
</script>


<!-- 简版  添加物料 -->
<script type="text/html" id="compactProductForm">
    <form lay-filter="compactProductForm" class="layui-form model-form"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px); margin-top: 20px; overflow-x: hidden;overflow-y: auto">
            <input name="id" type="hidden"/>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">规格系列</label>
                    <div class="layui-input-inline">
                        <select name="productId" lay-filter="getProduct" lay-search lay-verify="required"></select>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">物料类型</label>
                    <div class="layui-input-inline">
                        <input type="hidden" name="productTypeId" />
                        <input type="text" name="productTypeName" class="layui-input" readonly disabled/>
                    </div>
                    <!--<div class="layui-input-inline">
                        <select lay-filter="compactProductTypeId" id="compactProductTypeId" name="productTypeId"
                                lay-verify="required" lay-search="">
                            <option value="">请选择物料类型</option>
                        </select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <a href="#/product/productType" class="layui-btn layui-btn-xs" ew-event="closeDialog">
                            <i class="layui-icon layui-icon-addition"></i>
                        </a>
                    </div>-->
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">物料分类</label>
                    <div class="layui-input-inline">
                        <input type="hidden" name="productCategoryId" />
                        <input type="text" name="productCategoryName" class="layui-input"  readonly disabled/>
                    </div>
                    <!--<input name="productCategoryId" value="" type="hidden">
                    <div class="layui-input-inline" id="compactProductCategoryId"></div>
                    <div class="layui-form-mid layui-word-aux">
                        <a href="#/product/productCategory" class="layui-btn layui-btn-xs" ew-event="closeDialog">
                            <i class="layui-icon layui-icon-addition"></i>
                        </a>
                    </div>-->
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">物料名称</label>
                    <div class="layui-input-inline">
                        <input name="name" id="productName" class="layui-input" type="text" placeholder="请输入物料名称"
                               lay-verify="required" autocomplete="off"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">物料编号</label>
                    <div class="layui-input-inline">
                        <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号"
                               lay-verify="required" autocomplete="off"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">规格码</label>
                    <div class="layui-input-inline">
                        <input name="skuSpecValueNames" class="layui-input" type="text" placeholder="请输入规格码"
                               lay-verify="required" autocomplete="off"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">品牌</label>
                    <div class="layui-input-inline">
                        <select lay-filter="brandId" id="compactBrandId" name="brandId" lay-verify="required"
                                lay-search=""></select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <a href="#/product/productBrand" class="layui-btn layui-btn-xs" ew-event="closeDialog">
                            <i class="layui-icon layui-icon-addition"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">使用寿命</label>
                    <div class="layui-input-inline">
                        <input name="lifeSpan" class="layui-input" type="text" placeholder="请输入使用寿命" autocomplete="off"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">寿命单位</label>
                    <div class="layui-input-inline">
                        <select lay-filter="lifeUnit" name="lifeUnit">
                            <option value="">请选择寿命单位</option>
                            <option value="minute">分钟</option>
                            <option value="number">个数</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">库存计量方式</label>
                    <div class="layui-input-inline">
                        <select name="inventoryUnitType" lay-verify="required">
                            <option value="quantity">数量</option>
                            <option value="weight">重量</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">是否需要归还</label>
                    <div class="layui-input-inline">
                        <select name="returnType" lay-verify="required">
                            <option value="true">是</option>
                            <option value="false">否</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">供应商</label>
                    <div class="layui-input-inline">
                        <select name="supplierId" lay-search="">
                            <option value="">请选择供应商</option>
                        </select>
                    </div>
                </div>
            </div>
                <!--                <div class="layui-col-md4">-->
                <!--                    <label class="layui-form-label">存刀柜类型</label>-->
                <!--                    <div class="layui-input-inline">-->
                <!--                        <select name="storageKnifeType" lay-verify="required">-->
                <!--                            <option value="storage">存刀柜</option>-->
                <!--                            <option value="scraper">售刀柜</option>-->
                <!--                        </select>-->
                <!--                    </div>-->
                <!--                </div>-->
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">包装单位</label>
                    <div class="layui-input-inline" id="selectUnitId">
                        <select name="unitId" lay-filter="compactUnitId" lay-verify="required" required></select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <a href="#/product/productType" class="layui-btn layui-btn-xs" ew-event="closeDialog">
                            <i class="layui-icon layui-icon-addition"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">包装方案</label>
                    <div class="layui-input-inline" id="productPackId">
                        <select name="packId" lay-filter="getPackId" lay-verify="required" required></select>
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <a href="#/product/productType" class="layui-btn layui-btn-xs" ew-event="closeDialog">
                            <i class="layui-icon layui-icon-addition"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">包装价格</label>
                    <div class="layui-input-inline">
                        <input name="marketPrice" class="layui-input" type="text" placeholder="请输入包装价格"
                               lay-verify="required" autocomplete="off"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">基础单位单价</label>
                    <div class="layui-input-inline">
                        <input name="basePrice" class="layui-input" readonly disabled type="text" placeholder="基础单位单价"
                               autocomplete="off"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">归还时长阈值</label>
                    <div class="layui-input-inline">
                        <input name="returnThreshold" class="layui-input" type="text" placeholder="归还时长阈值" autocomplete="off"/>
                    </div>
                    <div class="layui-form-mid layui-word-aux">天</div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">呆滞时长阈值</label>
                    <div class="layui-input-inline">
                        <input name="lethargyThreshold" class="layui-input" type="text" placeholder="呆滞时长阈值" autocomplete="off"/>
                    </div>
                    <div class="layui-form-mid layui-word-aux">天</div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-inline">
                        <input name="remark" class="layui-input" type="text" placeholder="备注" autocomplete="off"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">采购预警</label>
                    <div class="layui-input-inline">
                        <input name="warningQuantity" class="layui-input" type="text" placeholder="采购预警"/>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">物料图片</label>
                <div id="compactProduct_path" class="uploadImgStyle"></div>
                <div id="compactProductUploadBtn" class="layui-btn" style="float: left;"><i
                        class="layui-icon">&#xe681;</i>上传图片
                </div>
                <input id="compactProductPicture" name="picture" type="hidden"/>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="compactProductFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 入库弹窗 -->
<script type="text/html" id="storageForm">
    <form class="layui-form" action="" lay-filter="storageForm" style="padding: 15px 20px 0 0;">
        <input name="skuCode" id="skuCode" type="hidden"/>
        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>入库仓库</label>
                <div class="layui-input-block">
                    <select name="warehouseId" required lay-verify="required" id="warehouseIdOption"
                            placeholder="请选择入库仓库">
                        <option value="">选择入库仓库</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>入库类型</label>
                <div class="layui-input-block">
                    <select name="warehouseInventoryTypeId" id="inType" required lay-verify="required" placeholder="请选择入库类型">
                        <option value="">选择入库类型</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>包装方案</label>
                <div class="layui-input-block">
                    <select name="packId" lay-filter="getPack" required lay-verify="required" id="packId" placeholder="请选择包装方案">
                        <option value="">选择包装方案</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>入库包装数</label>
                <div class="layui-input-block">
                    <input name="quantity" placeholder="请输入入库包装数" type="text" class="layui-input" lay-verify="required|integer" required autocomplete="off"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>入库基础数</label>
                <div class="layui-input-block">
                    <input name="quantityPack" type="text" class="layui-input" readonly/>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-submit lay-filter="storageFormSubmit">提交</button>
        </div>
    </form>
</script>

<!-- 出库弹窗 -->
<script type="text/html" id="outboundForm">
    <form class="layui-form" action="" lay-filter="outboundForm" style="padding: 15px 20px 0 0;">
        <input name="skuCode" id="skuCode" type="hidden"/>
        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>出库仓库</label>
                <div class="layui-input-block">
                    <select name="warehouseId" required lay-verify="required" id="warehouseIdOption"
                            placeholder="请选择出库仓库">
                        <option value="">选择出库仓库</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>出库类型</label>
                <div class="layui-input-block">
                    <select name="warehouseInventoryTypeId" id="outType" required lay-verify="required" placeholder="请选择出库类型">
                        <option value="">选择出库类型</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>包装方案</label>
                <div class="layui-input-block">
                    <select name="packId" lay-filter="getPack" required lay-verify="required" id="packId" placeholder="请选择入库仓库">
                        <option value="">选择包装方案</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>出库包装数</label>
                <div class="layui-input-block">
                    <input name="quantity" placeholder="请输入出库包装数" type="text" class="layui-input" lay-verify="required|integer"
                           required/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>出库基础数</label>
                <div class="layui-input-block">
                    <input name="quantityPack" type="text" class="layui-input" readonly/>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-submit lay-filter="outboundFormSubmit">提交</button>
        </div>
    </form>
</script>

<!-- 安全库存设置弹窗 -->
<script type="text/html" id="warningForm">
    <form class="layui-form" action="" lay-filter="warningForm" style="padding: 15px 20px 0 5px;">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 85px;">安全库存数量</label>
            <div class="layui-input-block" style="width: 220px;margin-left: 115px;">
                <input name="warningQuantity" placeholder="请输入最低安全库存数量" type="text" class="layui-input"
                       lay-verify="required" required autocomplete="off"/>
            </div>
            <!--            <div class="layui-form-item">-->
            <!--                <div class="layui-input-block">-->
            <!--                    <button class="layui-btn" lay-submit lay-filter="warningFormSubmit">提交</button>-->
            <!--                </div>-->
            <!--            </div>-->
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-submit lay-filter="warningFormSubmit">提交</button>
        </div>
    </form>
</script>

<!-- 入库详情弹窗 -->
<script type="text/html" id="storageDetailForm">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <!-- 表格 -->
                <table class="layui-table" id="storageDetailTable" lay-filter="storageDetailTable"></table>
            </div>
        </div>
    </div>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'layedit', 'tableTreeDj', 'newTree', 'laydate', 'upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var layedit = layui.layedit;
        var tableTree = layui.tableTreeDj;
        var newTree = layui.newTree;
        var laydate = layui.laydate;
        let productCategoryData = [];

        admin.selectSearch();

        $("body").delegate(".checkImg", "click", function () {
            admin.previewImg(".checkImg")
        });

        //物料类型
        admin.req('enterprise/product/admin/productType/list',{enterprise:0,limit:99999},res=>{
            if(res.code == 200){
                loadSelectHtml(res.data,'请选择物料类型','productTypeId','name');
            }else {
                loadSelectHtml([],'请选择物料类型','productTypeId','name')
            }
        });

        let productCategoryIdXmSelect = xmSelect.render({
            el: '#productCategoryIdXmSelect',
            tips: '请选择物料分类',
            model: {label: {type: 'text'}},
            filterable: true,
            tree: {
                show: true,
                strict: false,
                expandedKeys: [-1],
            },
            radio: true,
            clickClose: true,
            prop: {
                name: 'name',
                value: 'id',
                children: 'children'
            },
            on: (data)=> {
                if(data.isAdd){
                    $('input[name="productCategoryId"]').val(data.arr[0].id);
                }else {
                    $('input[name="productCategoryId"]').val('');
                }
                $('[lay-filter="formSubSearchLog"]').click();
            },
            data: []
        });
        //物料分类
        admin.req('enterprise/product/admin/productCategory/list',{enterprise:0,limit:99999},res=>{
            if(res.code == 200){
                let categoryList = [];
                for (let i = 0; i < res.data.length; i++) {
                    if (res.data[i].isDeleted) {
                        res.data[i].children = [];
                        categoryList.push(res.data[i])
                    }
                }
                productCategoryData = xmSelect.arr2tree(categoryList, "parentId", "id", "children", -1);
            }
            productCategoryIdXmSelect.update({data:productCategoryData})
        });




        //时间范围
        laydate.render({
            elem: '#pTime',
            type: 'date',
            range: true,
            done: function (value, date, endDate) {
                if (value) {
                    let dateValue = value.split(" - ");
                    $("#startTime").val(dateValue[0] + " 00:00:00");
                    $("#endTime").val(dateValue[1] + " 23:59:59");
                } else {
                    $("#startTime").val("");
                    $("#endTime").val("");
                }
                setTimeout(function() {$('[lay-filter="formSubSearchLog"]').click()}, 300);
            }
        });

        // let commonToolCabinetTableData = [];
        let queryExistProductData = ''; // 已导入的数据
        // 渲染表格
        var commonToolCabinetTb = table.render({
            elem: '#commonToolCabinetTable',
            url: config.base + 'enterprisecab/cabProduct/admin/mostUsedKnifeList/list',
            where: {categoryType: 'purchase'},
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            limit: 5,
            limits:[5,10,20,30,40,50,60,70,80],
            cellMinWidth: 100,
            id: 'commonToolCabinetTable',
            cols: [[
                //{type: 'checkbox'}
                {type: 'numbers', title: '序号', fixed: 'left'}
                , {
                    field: 'productPic',
                    title: '图片',
                    event: 'imgClick',
                    fixed: 'left',
                    align: 'center',
                    width: 110,
                    templet:function (d) {
                        if(d.productPic){
                            return '<img src="'+ d.productPic +'" style="cursor: pointer"/>';
                        }
                        return '<img src="assets/images/default-icon.png" style="cursor: pointer"/>';
                    }
                }
                , {field: 'skuName', title: '物料名称', fixed: 'left', width: 160}
                , {field: 'skuCode', title: '物料编号', width: 160, fixed: 'left'}
                , {field: 'oldSpecCode', title: '规格码', width: 160, fixed: 'left'}
                , {field: 'productBrandName', title: '品牌'}
                // , {field: 'productCode', title: '规格系列编码'}
                , {field: 'productName', title: '规格系列名称', width: 160}
                // , {field: 'skuSpecValueNames', title: 'sku规格编码'}
                , {field: 'productTypeName', title: '物料类型', width: 160}
                , {field: 'productCategoryName', title: '物料分类', width: 160}
                //, {field: 'supplyPrice', title: '供货价'}
                , {field: 'marketPrice', title: '市场价'}
                , {field: 'quantity', title: '库存数', width: 75}
                , {field: 'quantityCab', title: '在柜库存'}
                , {field: 'warningQuantity', title: '采购预警'}
                , {field: 'returnThreshold', title: '归还时长阈值', width: 120}
                , {field: 'lethargyThreshold', title: '呆滞时长阈值', width: 120}
                // , {field: 'oldSkuCode', title: '原物料编号'}
                //, {field: 'barcode', title: '商品条码'}
                // , {field: 'productTypeName', sort: true, title: '商品类型'}
                , {field: 'createTime', title: '创建时间', width: 160}
                , {align: 'center', toolbar: '#commonToolCabinetTableBar', title: '操作', width: 260, fixed: 'right'}
            ]],
            done: function (d) {
                // commonToolCabinetTableData = d.data
            }
        });
        form.render('select');


        // 工具条点击事件
        table.on('tool(commonToolCabinetTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detailsTableBarBtn') { //详情
                showListDetails(data);
            } else if (obj.event === 'skuListTableBarBtn') {
                showSkuList(data)
            } else if (obj.event === 'del') {
                delTool(data.id)
            } else if (obj.event === 'modifyTableBarBtn') { // 修改
                if (data.simplify == 0) {
                    showAddSelfCollectedGoods(data)
                } else if (data.simplify == 1) {
                    showAddProduct(data)
                }
            } else if (obj.event === 'imgClick') {
                imgModify(data);
            } else if (obj.event === 'cancellationTableBarBtn') {
                cancellation(data);
            } else if (obj.event === 'storageBtn') { // 入库
                showStorageModel(obj);
            }  else if (obj.event === 'outboundBtn') { // 出库
                showOutboundModel(obj);
            } else if (obj.event === 'warningBtn') { // 安全库存设置
                showWarningModel(obj);
            } else if (obj.event === 'storageDetailsBtn') { // 入库详情
                showStorageDetailsModel(obj);
            }
        });

        function imgModify(data) {
            admin.open({
                type: 1,
                area: ["900px", "500px"],
                offset: '65px',
                title: '修改图片',
                content: $('#imgModifyForm').html(),
                success: function () {
                    form.val('imgModifyForm', data);
                    $('#productPic_path').html('<img class="checkImg" style="max-height:350px; max-width: 700px" src="' + data.productPic + '"/>');
                    $('#productPicBtn').click(uploadImg('productPicBtn', 'productPic_path', 'productPic'));
                    form.on('submit(imgModifyFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req('enterprisecab/productCab/admin/productDetail/updatePicBySkuCode', {
                            skuCode: data.skuCode,
                            picUrl: d.field.productPic
                        }, res => {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('commonToolCabinetTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        })
                    })
                }
            })
        }

        // 获取导入数据
        function dataComparison() {
            admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/queryExistProduct', {}, function (res) {
                if (res.code == 200) {
                    queryExistProductData = res.data
                }
            }, 'GET', false, 'application/json; charset=utf-8');
        }


        // 详情弹窗
        function showListDetails(data) {
            admin.open({
                type: 1,
                area: ["1300px", "700px"],
                offset: '65px',
                title: '详情列表',
                content: $('#listDetails').html(),
                success: function () {
                    form.val('listDetailsForm', data);
                    var listDetailsFormTb = table.render({
                        elem: '#listDetailsFormTable',
                        url: config.base + 'enterprisecab/cabinet/admin/cellInventoryInoutDetail/list?skuCode=' + data.skuCode,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'spaceCode', title: '货道编号'}  // 暂时没有
                            , {field: 'cabCode', title: '柜子编号'}
                            , {field: 'cabName', title: '企业自定义名称'}
                            , {field: 'skuName', title: '物料名称'}
                            , {field: 'skuCode', title: '物料编号'}
                            , {field: 'skuSpecOld', title: '规格码'}
                            , {field: 'quantity', title: '库存'}
                            , {field: 'unitName', title: '单位'}
                        ]],
                        done: function (res) {

                        }
                    });
                }
            })
        }

        function cancellation(data) {
            layer.confirm('确定作废吗？', {
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/disable', data, function (res) {
                    if (res.code == 200) {
                        table.reload('commonToolCabinetTable');
                        layer.msg("作废成功！")
                    }else{
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'POST');
            })
        }


        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            commonToolCabinetTb.reload({where: data.field, page: {curr: 1}}, 'data');
            //return false;
        });


        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            var field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            productCategoryIdXmSelect.setValue([]);
            commonToolCabinetTb.reload({where: field, page: {curr: 1}}, 'data');
        });


        // 从平台添加按钮
        $("#fromPlatformAddBtn").click(() => {
            showFromPlatformAdd()
        });

        /*addPlatformBtn
        新 (从平台添加按钮)*/
        $("#addPlatformBtn").click(() => {
            showAddPlatform()
        });

        // 添加自采物料
        $("#fromOneselfPickAddBtn").click(() => {
            showFromOneselfPickAdd()
        });

        // 新  添加自采商品
        $('#addSelfCollectedGoodsBtn').click(() => {
            showAddSelfCollectedGoods()
        });

        //从本地仓库添加按钮
        $("#fromLocalWarehouseAddBtn").click(() => {
            showFromLocalWarehouseAdd()
        });

        // 简版  添加物料
        $("#addProductBtn").click(() => {
            showAddProduct()
        });

        // 批量删除
        $('#batchDelTool').click(function () {
            let checkRows = table.checkStatus('commonToolCabinetTable');
            let batchDelToolData = []
            if (checkRows.data.length == 0) {
                layer.msg('请选择需要批量删除的数据', {icon: 2});
            } else {
                checkRows.data.forEach(element => {
                    batchDelToolData.push(element.id)
                });
                delTool(batchDelToolData.toString())
            }
        });


        function delTool(_data) {
            layer.confirm('确定删除吗？', {
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/delete/' + _data, {}, function (data) {
                    layer.closeAll('loading');
                    if (data.code == 200) {
                        layer.msg(data.msg, {icon: 1});
                        table.reload('commonToolCabinetTable')
                        layer.closeAll('page');
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 显示从平台添加弹窗
        function showFromPlatformAdd(data) {
            admin.open({
                type: 1,
                area: ['1440px', "800px"],
                offset: '65px',
                title: '导入物料',
                id: "fromPlatformAddId",
                content: $('#fromPlatformAdd').html(),
                success: function () {
                    form.render();
                    var fromPlatformAddTb = table.render({
                        elem: '#fromPlatformAddTable',
                        url: config.base + 'enterprisecab/cabProduct/admin/mostUsedKnifeList/queryFromPlatform',
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'id', sort: true, title: 'ID'}
                            , {
                                field: 'picture',
                                title: '图片',
                                templet: (d) => "<img src='" + d.picture + "' width='80px' height='80px'/>"
                            }
                            , {field: 'name', title: '物料名称'}  // 暂时没有
                            , {field: 'productCode', title: '物料/物料编号'}
                            , {field: 'productTypeName', title: '类型'}
                            , {field: 'productCategoryExtName', title: '物料分类'}
                            , {field: 'brandName', title: '品牌'}
                            , {field: 'status', title: '状态'}
                            , {field: 'createTime', title: '发布时间'}
                            , {field: 'updateTime', title: '上架时间'}
                            , {align: 'center', toolbar: '#fromPlatformAddTableBar', title: '操作', width: 210}
                        ]],
                        done: function (res) {

                        }
                    });
                    dataComparison();

                    // 搜索
                    // fromPlatformAddSearch
                    form.on('submit(fromPlatformAddSearch)', function (data) {
                        fromPlatformAddTb.reload({where: data.field, page: {curr: 1}}, 'data');
                        return false;
                    });


                }
            });

            table.on('tool(fromPlatformAddTable)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detailsTableBarBtn') { //详情
                    showDetails(data);
                } else if (obj.event === 'skuListTableBarBtn') {  // sku
                    showSkuList(data, "plat")
                } else if (obj.event === 'manualImportBarBtn') { // 手动导入
                    if (data.productDetailList.length === 0) {
                        layer.msg('没有导入的物料', {icon: 2})
                    } else {
                        for (let i = 0; i < data.productDetailList.length; i++) {
                            for (let j = 0; j < queryExistProductData.length; j++) {
                                if (data.productDetailList[i].id == queryExistProductData[j]) {
                                    data.productDetailList.splice(i, 1)
                                    i--;
                                    break;
                                }
                            }
                        }

                        addManualImport(data.productDetailList)
                    }
                }
            });

            //从平台批量导入
            $('#addManualImportBtn').click(function () {
                let checkRows = table.checkStatus('fromPlatformAddTable');
                let newCheckRows = [];

                // console.log(checkRows.data.length == 0)
                // return false;
                if (checkRows.data.length == 0) {
                    layer.msg('请选择要批量导入的物料', {icon: 2})
                } else {
                    checkRows.data.map(item => {
                        if (item.productDetailList.length > 0) {
                            newCheckRows.push(item.productDetailList)
                        }
                    })

                    layer.load(2);
                    admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/addAll', JSON.stringify(newCheckRows), function (res) {
                        layer.closeAll('loading');
                        if (res.code == 200) {
                            layer.msg(res.msg, {icon: 1});
                            table.reload('fromPlatformAddTable');
                            table.reload('commonToolCabinetTable')
                            layer.closeAll('page');
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'POST', 'true', 'application/json; charset=utf-8');
                }
            })
        }

        /*
        * 新 从平台添加
        * */
        function showAddPlatform() {
            admin.open({
                type: 1,
                area: ['1550px', "800px"],
                offset: '65px',
                title: '从平台导入物料',
                content: $('#addPlatform').html(),
                success: function () {
                    let addPlatformData = [], existencePlatformData = [], existencePlatformObj = {};
                    //加载物料类型
                    admin.req('enterprisecab/cabProduct/admin/productType/list', {
                        type: 'knife',
                        page: 1,
                        limit: 9999
                    }, res => {
                        if (res.code === 200) {
                            loadAddPlatformSelectHtml(res.data, '请选择物料类型', 'productTypeId', 1)
                        }
                    }, 'GET');

                    //加载物料分类
                    admin.req('enterprisecab/cabProduct/admin/productCategory/list', {
                        type: 'knife',
                        page: 1,
                        limit: 9999
                    }, res => {
                        if (res.code === 200) {
                            loadAddPlatformSelectHtml(res.data, '请选择物料分类', 'productCategoryId', 1)
                        }
                    }, 'GET');


                    //加载物料单位
                    admin.req('enterprisecab/cabProduct/admin/productUnit/list', {
                        type: 'knife',
                        page: 1,
                        limit: 9999
                    }, res => {
                        if (res.code === 200) {
                            loadAddPlatformSelectHtml(res.data, '请选择物料单位', 'productUnitId', 1)
                        }
                    }, 'GET');

                    //加载品牌
                    admin.req('enterprisecab/cabProduct/admin/productBrand/list', {
                        type: 'knife',
                        page: 1,
                        limit: 9999
                    }, res => {
                        if (res.code === 200) {
                            loadAddPlatformSelectHtml(res.data, '请选择品牌', 'productBrandId', 1)
                        }
                    }, 'GET');

                    admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/queryExistProduct', {}, res => {
                        if (res.code === 200) {
                            existencePlatformData = [...res.data]
                        }
                    });

                    //渲染下拉框
                    form.render('select');
                    form.on('submit(addPlatformSearch)', function (data) {
                        if (data.field.productTypeId == '' && data.field.productCategoryId == '') {
                            layer.msg('请选择物料类型或者物料分类', {icon: '5'});
                            return false
                        }
                        layer.load(2);
                        addPlatformData = [];
                        admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/queryFromPlatform', data.field, res => {
                            layer.closeAll('loading');
                            if (res.code === 200) {
                                if (res.data.length > 0) {
                                    res.data.forEach(item => {
                                        item.productDetailList.forEach(listItem => {
                                            listItem.picture = item.picture;
                                            listItem.brandName = item.brandName;
                                            listItem.productCategoryName = item.productCategoryName;
                                            if (existencePlatformData.indexOf(listItem.id) < 0) {
                                                listItem.existence = false;
                                            } else {
                                                listItem.existence = true;
                                            }
                                            addPlatformData.push(listItem)
                                        })
                                    });
                                }
                                table.reload('addPlatformTable', {data: addPlatformData});
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                        return false;
                    });

                    let addPlatformTb = table.render({
                        elem: '#addPlatformTable',
                        limit: Number.MAX_VALUE,
                        data: addPlatformData,
                        cellMinWidth: 100,
                        height: 500,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'skuCode', title: '物料编号', width: 120}
                            , {
                                field: 'picture',
                                title: '图片',
                                width: 115,
                                templet: d => '<img src="' + d.picture + '"/>'
                            }
                            , {field: 'skuName', title: '物料名称', width: 150}
                            , {field: 'skuSpecValueNames', title: '规格码', width: 120}
                            , {field: 'storePrice', title: '当前单价', width: 100}
                            , {field: 'marketPrice', title: '市场指导价', width: 100}
                            , {field: 'barcode', title: '货品条码', width: 100}
                            , {field: 'brandName', title: '所属品牌', width: 90}
                            , {field: 'productCategoryName', title: '类型', width: 100}
                            , {
                                field: 'existence',
                                title: '状态',
                                width: 80,
                                templet: d => d.existence ? '已导入' : '<span style="color: red">未导入</span>'
                            }
                            , {align: 'left', toolbar: '#addPlatformTableBar', title: '操作', width: 80}
                        ]],
                        done: function (res) {
                        }
                    });

                    $('#addPlatformImportBtn').click(() => {
                        let checkStatus = table.checkStatus('addPlatformTable');
                        let checkStatusData = checkStatus.data.filter(item => item.existence == false);

                        if (checkStatus.data.length > 0) {
                            if (checkStatusData.length > 0) {
                                showSelectAddPlatform(checkStatusData)
                            } else {
                                layer.msg('物料已导入', {icon: 5})
                            }
                        } else {
                            layer.msg('请选择要导入的物料', {icon: 5})
                        }
                    })
                }
            });
        }

        function showSelectAddPlatform(data) {
            admin.open({
                type: 1,
                area: ['1500px', "750px"],
                offset: '85px',
                title: '从平台导入物料',
                content: $('#selectAddPlatform').html(),
                success: function () {
                    console.log(data)
                    form.val('selectAddPlatformForm', data[0]);
                    let arr2tree;
                    admin.req('enterprise/product/admin/productCategory/getProductCategoryByType', {type: 0}, function (res) {
                        let categoryList = []
                        for (let i = 0; i < res.data.length; i++) {
                            if (res.data[i].isDeleted) {
                                res.data[i].children = [];
                                categoryList.push(res.data[i])
                            }
                        }
                        arr2tree = xmSelect.arr2tree(categoryList, "parentId", "id", "children", -1);
                    }, 'get', false);

                    let smlSelectInstans = xmSelect.render({
                        el: '#localProductCategoryId',
                        model: {label: {type: 'text'}},
                        radio: true,
                        clickClose: true,
                        filterable: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2tree;
                        },
                        on(data) {
                            let parentId = data.arr.length > 0 ? data.change[0].id : -1;
                            $("input[name='localProductCategoryId']").val(parentId);
                        }
                    });

                    admin.req('enterprise/product/admin/productType/getProductTypeByType', {type: 0}, res => {
                        if (res.code === 200) {
                            let typeList = [];
                            res.data.forEach(item => {
                                // 如果没有被停用
                                if (item.isDeleted) {
                                    typeList.push(item)
                                }
                            })
                            loadSelectAddPlatformFormSelectHtml(typeList, '请选择物料类型', 'productTypeId', 1)
                        }

                    }, 'GET');

                    admin.req('enterprise/product/admin/productUnit/getAllUnit', {type: 0}, res => {
                        if (res.code === 200) {
                            loadSelectAddPlatformFormSelectHtml(res.data, '请选择物料单位', 'unitId', 1)
                        }

                    }, 'GET');

                    admin.req('enterprise/product/admin/productBrand/getAllProductBrandByType', {type: 0}, res => {
                        if (res.code === 200) {
                            let brandList = []
                            res.data.forEach(item => {
                                if (item.isDeleted) {
                                    brandList.push(item)
                                }
                            })
                            loadSelectAddPlatformFormSelectHtml(brandList, '请选择品牌', 'brandId', 1)
                        }

                    }, 'GET');

                    //渲染下拉框
                    form.render('select');
                    let selectAddPlatformTb = table.render({
                        elem: '#selectAddPlatformTable',
                        limit: Number.MAX_VALUE,
                        height: 430,
                        data: data,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号', width: 50}
                            , {field: 'skuCode', title: '物料编号', width: 120}
                            , {
                                field: 'picture',
                                title: '平台SKU图片',
                                width: 115,
                                templet: d => '<img src="' + d.picture + '"/>'
                            }
                            , {field: 'skuName', title: '物料名称', width: 150}
                            , {field: 'skuSpecValueNames', title: '规格码', width: 120}
                            , {field: 'storePrice', title: '当前单价', width: 100}
                            , {field: 'marketPrice', title: '市场指导价', width: 100}
                            , {field: 'barcode', title: '货品条码', width: 100}
                            , {field: 'brandName', title: '所属品牌', width: 90}
                            , {field: 'productCategoryName', title: '平台类型', width: 100}
                            , {
                                field: 'existence',
                                title: '状态',
                                width: 80,
                                templet: d => d.existence ? '已导入' : '<span style="color: red">未导入</span>'
                            }
                            , {align: 'left', toolbar: '#addPlatformTableBar', title: '操作', width: 100}
                        ]],
                        done: function (res) {

                        }
                    });

                    form.on('submit(selectAddPlatformSubmitBtn)', d => {
                        layer.load(2);
                        let selectAddPlatformTableData = table.cache["selectAddPlatformTable"];
                        selectAddPlatformTableData.forEach(item => {
                            item.brandId = d.field.brandId;
                            item.productTypeId = d.field.productTypeId;
                            item.unitId = d.field.unitId;
                            item.productCategoryId = d.field.localProductCategoryId;
                            if (d.field.isSpecificationCode == 0) {
                                item.skuSpecValueNames = '';
                                item.skuSpecValue = '';
                            }
                            if (JSON.stringify(item.pricingMethod) == "{}") {
                                item.pricingMethod = undefined;
                                item.pricingMethodDesc = undefined;
                            }
                        });
                        // console.log(selectAddPlatformTableData);
                        // return  false;
                        //
                        admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/add', JSON.stringify(selectAddPlatformTableData), res => {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    })
                }
            })

        }

        function loadAddPlatformSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                }
            }
            $("form.addPlatform select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

        function loadSelectAddPlatformFormSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                }
            }
            $("form.selectAddPlatformForm select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }


        /**
         * 加载地址HTML
         * @param data 下拉菜单数据
         * @param tips select 默认提示
         * @param htmltarget html要插入的位置
         * @param name  下拉框需要显示值的属性
         */
        function loadSelectHtml(data, tips, htmltarget, name) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                let isFinalCategory = '';
                if (data[i].isFinalCategory != undefined) {
                    isFinalCategory = `isFinal=` + data[i].isFinalCategory;
                }
                html += `<option value='${data[i].id}' ${isFinalCategory}>${data[i][name]}</option>`;
            }
            $("[name='" + htmltarget + "']").html(html);
            form.render();
        }

        // 添加自采商品
        function showFromOneselfPickAdd(data) {
            admin.open({
                type: 1,
                area: '1368px',
                offset: '65px',
                title: data ? '修改物资信息' : '添加物资信息',
                content: $('#productForm').html(),
                success: function () {
                    var dbSkuMap = new Map();
                    productSpecValueByProductSpecValueIds.clear();
                    productSpecValueByProductSpecValueIdsStr = '';
                    localMap.clear();
                    localSkuData = [];

                    //加载物料类型
                    admin.req('enterprise/product/admin/productType/getProductTypeByType', {type: 0}, function (res) {
                        let typeList = [];
                        res.data.forEach(item => {
                            // 如果没有被停用
                            if (item.isDeleted) {
                                typeList.push(item)
                            }
                        })
                        loadSelectHtml(typeList, "请选择物料类型", "productTypeId", "name");
                        if (data) {
                            $("#productTypeId").val(data.productTypeId);
                            form.render('select');
                        }
                    }, 'get', false);

                    //加载物料分类树级菜单
                    var arr2tree;
                    admin.req('enterprise/product/admin/productCategory/getProductCategoryByType', {type: 0}, function (res) {
                        let categoryList = []
                        for (let i = 0; i < res.data.length; i++) {
                            if (res.data[i].isDeleted) {
                                res.data[i].children = [];
                                categoryList.push(res.data[i])
                            }
                        }
                        arr2tree = xmSelect.arr2tree(categoryList, "parentId", "id", "children", -1);
                    }, 'get', false);

                    var selectedData = function (treeData, targetId) {

                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    }

                    if (data) {
                        selectedData(arr2tree, data.productCategoryId);
                    }

                    var smlSelectInstans = xmSelect.render({
                        el: '#productCategoryId',
                        model: {label: {type: 'text'}},
                        radio: true,
                        clickClose: true,
                        filterable: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2tree;
                        },
                        on(data) {
                            let parentId = data.arr.length > 0 ? data.change[0].id : -1;
                            $("input[name='productCategoryId']").val(parentId);
                        }
                    });

                    //加载扩展物料分类树级菜单
                    var arr2treeExt;
                    admin.req('enterprise/product/admin/productCategory/getProductCategoryByType', {type: 0}, function (res) {
                        let categoryList = []
                        for (let i = 0; i < res.data.length; i++) {
                            if (res.data[i].isDeleted) {
                                res.data[i].children = [];
                                categoryList.push(res.data[i])
                            }
                        }
                        arr2treeExt = xmSelect.arr2tree(categoryList, "parentId", "id", "children", -1);
                    }, 'get', false);

                    var selectedDataExt = function (treeData, targetId) {
                        var ids = targetId.split(",");
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            for (var t = 0; t < ids.length; t++) {
                                if (ids[t] == nodeId) {
                                    treeData[k].selected = true;
                                    continue;
                                } else {
                                    if (treeData[k].children && treeData[k].children != '') {
                                        selectedData(treeData[k].children, ids[t]);
                                    }
                                }
                            }
                        }
                    }

                    if (data) {
                        selectedDataExt(arr2treeExt, data.productCategoryExtId);
                    }
                    var smlSelectInstansExt = xmSelect.render({
                        el: '#productCategoryExt',
                        model: {label: {type: 'text'}},
                        //radio: true,
                        clickClose: true,
                        filterable: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2treeExt;
                        }
                    });


                    //加载品牌
                    admin.req('enterprise/product/admin/productBrand/getAllProductBrandByType', {type: 0}, function (res) {
                        let brandList = []
                        res.data.forEach(item => {
                            if (item.isDeleted) {
                                brandList.push(item)
                            }
                        })
                        loadSelectHtml(brandList, "请选择品牌", "brandId", "name");
                        if (data) {
                            $("#brandId").val(data.brandId);
                            form.render('select');
                        }
                    }, 'get', false);

                    var productAttrData;

                    form.on('select(productTypeId)', function (data) {
                        admin.req('enterprise/product/admin/productAttribute/getProductAttrByProductTypeId', {productTypeId: data.value}, function (res) {
                            productAttrData = res.data;
                        }, 'get', false);
                        //创建物料属性
                        createProductAttr(productAttrData);
                        //创建物料规格
                        createProductSpec(data);

                        //加载物料单位
                        admin.req('enterprise/product/admin/productUnit/getProductUnitByType', {
                            type: 0,
                            productTypeId: data.value
                        }, function (res) {
                            loadSelectHtml(res.data, "请选择单位", "unitId", "name");
                            if (data) {
                                $("#unitId").val(data.unitId);
                                form.render('select');
                            }
                        }, 'get', false);
                    });
                    form.on('checkbox(productSpec)', function (data) {
                        if (data.elem.checked) {
                            admin.req('enterprise/product/admin/productSpecValue/getProductSpecValueByProductSpecId', {productSpecId: data.value}, function (res) {
                                //console.log("规格值：" + data.value);
                                var html = loadSpecValueHtml(res.data, data.elem.title, data.value);
                                //console.log(html);
                                $("[name='productSpecValueHtml']").html($("[name='productSpecValueHtml']").html() + html);
                                form.render();
                            }, 'get', false);
                        } else {
                            $("[name='specValue" + data.elem.title + "']").html("");
                            form.render();
                        }
                        createProductSpecValueSku(dbSkuMap);
                    });

                    form.on('checkbox(productSpecValue)', function (data) {

                        createProductSpecValueSku(dbSkuMap);

                    });


                    //查询企业信息
                    var enterpriseInfo;
                    admin.req('enterprise/system/admin/enterpricceId/getEnterpricceIdVO', {}, function (res) {
                        enterpriseInfo = res.data;
                    }, 'get', false);
                    if ("" == enterpriseInfo || null == enterpriseInfo) {
                        layer.msg("企业信息获取异常", {icon: 1});
                        return;
                    }
                    //var productCode = $("input[name='productCode']").val();
                    upload.render({
                        elem: '#btnUpload14'
                        , url: config.upload_url + 'uploadFile'
                        , data: {"path": enterpriseInfo.enterpriseCode + "/"}
                        , accept: 'file'
                        , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                        , headers: {Authorization: 'Bearer ' + config.getToken()}
                        , done: function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                var imagUrl = res.data.url;
                                // if(imagUrl){
                                //     imagUrl=imagUrl.substring(imagUrl.indexOf('/')+1)
                                // }
                                $('#btnUpload14_path').html('<img src="' + imagUrl + '" style="height: 50px;" />');
                                $('#picture').val(imagUrl);
                            } else if (res.code == 502) {
                                return location.replace('admin/login.html');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    });

                    if (data && data.picture) {
                        $('#btnUpload14_path').html('<img src="' + data.picture + '" style="height: 50px;" />');
                    }
                    var layeditIndex18 = layedit.build('description', {
                        uploadImage: {
                            url: config.upload_url + 'uploadFile',
                            type: 'post',
                            data: {"path": enterpriseInfo.enterpriseCode + "/"},
                            base: config.base,
                            before: function (obj) {
                                layer.load(); //上传loading
                                this.headers = {Authorization: 'Bearer ' + config.getToken()};
                                this.data = {"path": enterpriseInfo.enterpriseCode + "/"};
                            }
                        }
                    });

                    if (data) {
                        $("#productCode_edit").attr("disabled", "disabled");
                        form.render();
                        layedit.setContent(layeditIndex18, data.description, false);

                        //回显商品属性
                        admin.req('enterprise/product/admin/productAttribute/getProductAttrByProductTypeId', {productTypeId: data.productTypeId}, function (res) {
                            createProductAttr(res.data);
                        }, 'get', false);

                        for (var k = 0; k < data.productDetailAttribute.length; k++) {
                            var attrObj = data.productDetailAttribute[k];
                            var arrrValueObj = attrObj.productDetailAttributeValue;
                            if (attrObj.style == 'single') {
                                $("#productAttrValue" + attrObj.attrId).val(arrrValueObj[0].valueId);
                            }
                            if (attrObj.style == 'many') {
                                var checkboxArr = $("input[name='productAttrValue" + attrObj.attrId + "']");
                                for (let j = 0; j < checkboxArr.length; j++) {
                                    for (var i = 0; i < arrrValueObj.length; i++) {
                                        if ($(checkboxArr[j]).val() == arrrValueObj[i].valueId) {
                                            $(checkboxArr[j]).prop("checked", "checked")
                                        }
                                    }
                                }
                            }
                            if (attrObj.style == 'text') {
                                $("#productAttrValue" + attrObj.attrId).val(attrObj.attrValue);
                            }
                        }
                        form.render();
                        //回显SKU明细
                        //var itemSub = data.productDetialList;
                        admin.req('enterprise/product/admin/productDetail/getProductDetailByProductId', {productId: data.id}, function (res) {
                            //初始化物料规格
                            var itemSub = res.data;
                            //去重的商品规格ID
                            var productSpecId = [];
                            var productSpecValueId = [];
                            for (var i = 0; i < itemSub.length; i++) {
                                var arrSpec = itemSub[i].skuSpec.split("_");
                                var arrSpecValue = itemSub[i].skuSpecValue.split("_");
                                for (var j = 0; j < arrSpec.length; j++) {
                                    productSpecId.push(arrSpec[j]);
                                }
                                for (var j = 0; j < arrSpecValue.length; j++) {
                                    productSpecValueId.push(arrSpecValue[j]);
                                }
                            }
                            var skuSpecId = unique(productSpecId);
                            createProductSpec({value: data.productTypeId});

                            var checkboxArr = $("input[name='productSpec']");
                            for (let j = 0; j < checkboxArr.length; j++) {
                                for (var i = 0; i < skuSpecId.length; i++) {
                                    if ($(checkboxArr[j]).val() == skuSpecId[i]) {
                                        $(checkboxArr[j]).prop("checked", "checked")
                                    }
                                }
                            }


                            //初始化物料规格值
                            var productSpecMap = new Map();
                            admin.req('enterprise/product/admin/productSpec/getProductSpecByProductTypeId', {productTypeId: data.productTypeId}, function (res) {

                                var data = res.data;
                                for (var i = 0; i < data.length; i++) {
                                    productSpecMap.set(data[i].id, data[i].name);
                                }

                            }, 'get', false);
                            //去重
                            for (var i = 0; i < skuSpecId.length; i++) {
                                //创建物料规格值列表
                                admin.req('enterprise/product/admin/productSpecValue/getProductSpecValueByProductSpecId', {productSpecId: skuSpecId[i]}, function (res) {
                                    //console.log("规格值：" + data.value);
                                    var html = loadSpecValueHtml(res.data, productSpecMap.get(skuSpecId[i]), skuSpecId[i]);
                                    //console.log(html);
                                    $("[name='productSpecValueHtml']").html($("[name='productSpecValueHtml']").html() + html);
                                }, 'get', false);
                            }
                            form.render();

                            //商品规格值回显
                            var skuSpecValueId = unique(productSpecValueId);
                            for (var i = 0; i < skuSpecId.length; i++) {
                                var checkboxArr = $("input[name='productSpecValue" + skuSpecId[i] + "']");
                                for (let j = 0; j < checkboxArr.length; j++) {
                                    for (var k = 0; k < skuSpecValueId.length; k++) {
                                        if ($(checkboxArr[j]).val() == skuSpecValueId[k]) {
                                            $(checkboxArr[j]).prop("checked", "checked")
                                        }
                                    }
                                }
                            }


                            //物料SKU数据回填
                            itemSub.forEach(item => {
                                dbSkuMap.set(item.skuSpecValue, item);
                            })
                            createProductSpecValueSku(dbSkuMap);

                            for (var k = 0; k < itemSub.length; k++) {
                                $("#skuName" + itemSub[k].skuSpecValue).val(itemSub[k].skuName);
                                $("#skuCode" + itemSub[k].skuSpecValue).val(itemSub[k].skuCode);
                                $("#spPrice" + itemSub[k].skuSpecValue).val(itemSub[k].spPrice);
                                $("#marketPrice" + itemSub[k].skuSpecValue).val(itemSub[k].marketPrice);
                                $("#supplyPrice" + itemSub[k].skuSpecValue).val(itemSub[k].supplyPrice);
                                $("#activityPrice" + itemSub[k].skuSpecValue).val(itemSub[k].activityPrice);
                                $("#enterpriceCode" + itemSub[k].skuSpecValue).val(itemSub[k].enterpriceCode);
                                $("#barcode" + itemSub[k].skuSpecValue).val(itemSub[k].barcode);
                                $("#skuId" + itemSub[k].skuSpecValue).val(itemSub[k].id);
                                form.render();
                            }

                        }, 'get', false);

                    }


                    form.val('productForm', data);
                    // 表单提交事件
                    form.on('submit(productFormSubmit)', function (d) {
                        //console.log(d.field);
                        layer.load(2);
                        //获取SKU行数据
                        //获取所有行
                        let row = $("[lay-id=productSkuTable] table tbody tr");
                        //遍历所有行
                        let listData = [];
                        for (var i = 0; i < row.length; i++) {
                            //console.log(row);skuSpesValueName
                            var skuSpec = row.eq(i).find("input").eq(0).val();
                            var skuSpecValue = row.eq(i).find("input").eq(1).val();
                            var skuName = row.eq(i).find("input").eq(2).val();
                            // var skuSpecValueNames = row.eq(i).find("input").eq(3).val();
                            var skuCode = row.eq(i).find("input").eq(4).val();
                            var spPrice = row.eq(i).find("input").eq(5).val();
                            var marketPrice = row.eq(i).find("input").eq(6).val();
                            var supplyPrice = row.eq(i).find("input").eq(7).val();
                            var activityPrice = row.eq(i).find("input").eq(8).val();
                            var enterpriceCode = row.eq(i).find("input").eq(9).val();
                            var barcode = row.eq(i).find("input").eq(10).val();
                            let skuSpecValueNames = row.eq(i).find("span[name='skuSpecValueNamesSpan']").text();
                            let oldSpecCode = row.eq(i).find("input").eq(12).val();

                            let subData = {
                                skuSpec: skuSpec,
                                skuSpecValue: skuSpecValue,
                                skuName: skuName,
                                skuSpecValueNames: skuSpecValueNames,
                                skuCode: skuCode,
                                spPrice: spPrice,
                                marketPrice: marketPrice,
                                supplyPrice: supplyPrice,
                                activityPrice: activityPrice,
                                enterpriceCode: enterpriceCode,
                                barcode: barcode
                            }
                            listData.push(subData)
                        }
                        //console.log(listData)
                        d.field.productDetailForm = listData;
                        //获取商品属性
                        var attrArry = [];
                        var productAttrData;
                        var productTypeId = $("#productTypeId").val();
                        admin.req('enterprise/product/admin/productAttribute/getProductAttrByProductTypeId', {productTypeId: productTypeId}, function (res) {
                            productAttrData = res.data;
                        }, 'get', false);
                        for (var k = 0; k < productAttrData.length; k++) {
                            var obj = productAttrData[k];
                            //多选 获取值
                            var subAttrArry = [];
                            if (obj.style == 'many') {
                                $("input:checkbox[name='productAttrValue" + obj.id + "']:checked").each(function (i) {
                                    var subArrrObj = {
                                        attrId: obj.id,
                                        value: $(this).attr('title'),
                                        valueId: $(this).val()
                                    };
                                    subAttrArry.push(subArrrObj);
                                });
                                if (subAttrArry.length > 0) {
                                    var attrObj = {
                                        attrId: obj.id,
                                        attrName: obj.name,
                                        productDetailAttributeValueForm: subAttrArry,
                                        style: 0
                                    };
                                    attrArry.push(attrObj);
                                }
                            }
                            //单选 获取值
                            if (obj.style == 'single') {
                                var selectVal = $("#productAttrValue" + obj.id).val();
                                var selectName = $("#productAttrValue" + obj.id).find("option:selected").text();

                                if (selectVal != '') {
                                    var subArrrObj = {
                                        attrId: obj.id,
                                        value: selectName,
                                        valueId: selectVal
                                    };
                                    subAttrArry.push(subArrrObj);
                                }
                                if (subAttrArry.length > 0) {
                                    var attrObj = {
                                        attrId: obj.id,
                                        attrName: obj.name,
                                        productDetailAttributeValueForm: subAttrArry,
                                        style: 1
                                    };
                                    attrArry.push(attrObj);
                                }
                            }

                            //文本 获取值
                            if (obj.style == 'text') {
                                var selectVal = $("#productAttrValue" + obj.id).val();
                                if (selectVal != '') {
                                    var attrObj = {
                                        attrId: obj.id,
                                        attrName: obj.name,
                                        attrValue: selectVal,
                                        style: 2
                                    };
                                    attrArry.push(attrObj);
                                }
                            }
                        }

                        d.field.productDetailAttributeForm = attrArry;

                        d.field.productCategoryExtId = d.field.select;
                        d.field.description = layedit.getContent(layeditIndex18);
                        var a = JSON.stringify(d.field);
                        admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/addProduct', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('commonToolCabinetTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }

            });
        }

        //显示从本地仓库添加弹窗
        function showFromLocalWarehouseAdd() {
            admin.open({
                type: 1,
                area: ['1440px', "800px"],
                offset: '65px',
                title: '本地仓库导入物料',
                content: $('#fromLocalWarehouseFormAdd').html(),
                success: function () {
                    form.render();
                    var fromPlatformAddTb = table.render({
                        elem: '#fromLocalWarehouseAddTable',
                        url: config.base + 'enterprise/product/admin/product/list?isLocalImport=0',
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'id', sort: true, title: 'ID'}
                            , {
                                field: 'picture',
                                title: '图片',
                                templet: (d) => "<img src='" + d.picture + "' width='80px' height='80px'/>"
                            }
                            , {field: 'name', title: '物料名称'}  // 暂时没有
                            , {field: 'productCode', title: '物料/物料编号'}
                            , {field: 'productTypeName', title: '类型'}
                            , {field: 'productCategoryExtName', title: '物料分类'}
                            , {field: 'brandName', title: '品牌'}
                            , {field: 'status', title: '状态'}
                            , {field: 'createTime', title: '发布时间'}
                            , {field: 'updateTime', title: '上架时间'}
                            , {align: 'center', toolbar: '#fromLocalWarehouseTableBar', title: '操作', width: 210}
                        ]],
                        done: function (res) {

                        }
                    });
                    dataComparison();

                    // 搜索
                    // fromLocalWarehouseSearch
                    form.on('submit(fromLocalWarehouseSearch)', function (data) {
                        fromPlatformAddTb.reload({where: data.field, page: {curr: 1}}, 'data');
                        return false;
                    });


                }
            });

            table.on('tool(fromLocalWarehouseAddTable)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detailsTableBarBtn') { //详情
                    showDetails(data);
                } else if (obj.event === 'skuListTableBarBtn') {  // sku
                    showSkuList(data, 'local')
                } else if (obj.event === 'manualImportBarBtn') { // 手动导入
                    if (data.productDetailList.length === 0) {
                        layer.msg('没有导入的物料', {icon: 2})
                    } else {
                        for (let i = 0; i < data.productDetailList.length; i++) {
                            for (let j = 0; j < queryExistProductData.length; j++) {
                                if (data.productDetailList[i].id == queryExistProductData[j]) {
                                    data.productDetailList.splice(i, 1)
                                    i--;
                                    break;
                                }
                            }
                        }

                        addLocalManualImport(data.productDetailList)
                    }
                }
            });

            //从本地批量导入
            $('#addLocalImportBtn').click(function () {
                let checkRows = table.checkStatus('fromLocalWarehouseAddTable');
                let newCheckRows = [];
                if (checkRows.data.length == 0) {
                    layer.msg('请选择要批量导入的物料', {icon: 2})
                } else {
                    checkRows.data.map(item => {
                        if (item.productDetailList.length > 0) {
                            newCheckRows.push(item.productDetailList)
                        }
                    })
                    for (let i = 0; i < newCheckRows[0].length; i++) {
                        newCheckRows[0][i].isSyns = ""
                        newCheckRows[0][i].creator = ''
                    }
                    layer.load(2);
                    admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/addAllLocalManualImport', JSON.stringify(newCheckRows), function (res) {
                        layer.closeAll('loading');
                        if (res.code == 200) {
                            layer.msg(res.msg, {icon: 1});
                            table.reload('fromLocalWarehouseAddTable');
                            table.reload('commonToolCabinetTable')
                            layer.closeAll('page');
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'POST', 'true', 'application/json; charset=utf-8');
                }
            })
        }


        // 从平台添加 详情弹窗
        function showDetails(data) {
            admin.open({
                type: 1,
                area: "900px",
                offset: '65px',
                title: '详情列表',
                content: $('#details').html(),
                success: function () {
                    $("#xq_description").html(data.description)
                    form.val('detailsForm', data);
                }
            })
        }

        // sku弹窗
        function showSkuList(data, type) {
            let skuListTable1Data = [];
            skuListTable1Data.push(data);
            admin.open({
                type: 1,
                area: "1500px",
                offset: '65px',
                title: 'SKU列表',
                content: $('#skuList').html(),
                success: function () {
                    var skuListTable1 = table.render({
                        elem: '#skuListTable1',
                        data: skuListTable1Data,
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'id', sort: true, title: 'ID'}
                            , {
                                field: 'picture',
                                title: '图片',
                                templet: (d) => "<img src='" + d.picture + "' width='80px' height='80px'/>"
                            }
                            , {field: 'name', title: '物料名称'}
                            , {field: 'productCode', title: '规格码'}
                            , {field: 'productTypeName', title: '物料类型'}
                            , {field: 'brandCode', title: '所属供应商'}
                            , {field: '', title: '重量'}
                            , {field: '', title: '状态'}
                            , {field: 'createTime', title: '发布时间'}
                            , {field: '', title: '上架时间'}
                        ]]
                    });

                    if (data.productDetailList.length > 0) {
                        for (let i = 0; i < data.productDetailList.length; i++) {
                            if (queryExistProductData.length > 0) {
                                for (let j = 0; j < queryExistProductData.length; j++) {
                                    if (data.productDetailList[i].id == queryExistProductData[j]) {
                                        data.productDetailList[i].skuStateDescribe = '已导入'
                                        data.productDetailList[i].skuStateCode = true
                                        break;
                                    } else {
                                        data.productDetailList[i].skuStateDescribe = '未导入'
                                        data.productDetailList[i].skuStateCode = false
                                    }
                                }
                            } else {
                                data.productDetailList[i].skuStateDescribe = '未导入'
                                data.productDetailList[i].skuStateCode = false
                            }

                        }
                    }

                    var skuListTable2 = table.render({
                        elem: '#skuListTable2',
                        data: data.productDetailList,
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'skuCode', title: '物料编号'}
                            , {field: 'skuName', title: '物料名称'}
                            , {field: 'skuSpecValueNames', title: '规格'}
                            , {field: 'activityPrice', title: '会员价'}
                            , {field: 'marketPrice', title: '市场指导价'}
                            , {field: 'stockNumber', title: '在售库存'}
                            , {field: 'barcode', title: '货品条码'}
                            , {
                                field: 'skuStateDescribe', title: '状态', templet: function (d) {
                                    return d.skuStateCode ? d.skuStateDescribe : "<span style='color:red'>" + d.skuStateDescribe + "</span>"
                                }
                            }
                            , {title: '操作', toolbar: "#skuListTwoTableBar", align: 'center'}
                        ]],
                    });

                    // 工具条点击事件
                    table.on('tool(skuListTable2)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'remSkuListTableBarBtn') { //详情
                            delTool(data.id)
                        } else if (obj.event === 'addSkuListTableBarBtn' && type === 'plat') {
                            addManualImport([data])
                        } else if (obj.event === 'addSkuListTableBarBtn' && type === 'local') {
                            addLocalManualImport([data])
                        }
                    });
                }
            })

        }


        // 导入物料（手动导入和批量导入）
        function addManualImport(data) {
            //console.log('data',data)
            //return false;
            if (data.length == 0) {
                layer.msg('没有可导入的数据', {icon: 2});
            } else {
                for (const key in data) {
                    delete data[key].isSyns;
                    delete data[key].creator;
                }
                layer.load(2);
                admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/add', JSON.stringify(data), function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('fromPlatformAddTable');
                        table.reload('commonToolCabinetTable')
                        layer.closeAll('page');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'POST', 'true', 'application/json; charset=utf-8');
            }
        }

        // 本地添加导入物料（手动导入和批量导入）
        function addLocalManualImport(data) {
            //console.log('data',data)
            //return false;
            if (data.length == 0) {
                layer.msg('没有可导入的数据', {icon: 2});
            } else {
                for (const key in data) {
                    delete data[key].isSyns;
                    delete data[key].creator;
                }
                layer.load(2);
                admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/addLocalManualImport', JSON.stringify(data), function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('fromPlatformAddTable');
                        table.reload('commonToolCabinetTable')
                        layer.closeAll('page');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'POST', 'true', 'application/json; charset=utf-8');
            }
        }

        function unique(arr) {
            return arr.filter((item, index) => {
                console.log(item, index);
                // console.log(arr.indexOf(item)+'---'+index
                // 第一次 cc 索引2 过滤后的索引2
                // 第二次 cc 索引2 过滤后的索引3
                // 后面去重以此类推
                return arr.indexOf(item) == index
            })
        }

        function loadSpecValueHtml(data, name, productSpecId) {
            let html = "";
            if (!data || data == null) {
                layer.msg("物料类型规格值为空,请先前往配置物料规格值！", {icon: 2});
                return;
            }
            html += '<div style="margin-top: 20px" name="specValue' + name + '">';
            html += '<div class="layui-form-item">';
            html += '<label class="layui-form-label" style="padding-left: 0;text-align: left;">' + name + ':</label>';
            html += '<div class="layui-input-block">';

            for (let i = 0; i < data.length; i++) {
                html += '<input lay-filter="productSpecValue" type="checkbox" name  = "productSpecValue' + productSpecId + '"  value="' + data[i].id + '" lay-skin="primary" title="' + data[i].value + '">';
            }
            html += '</div>';
            html += '</div>';
            html += '</div>';
            //console.log(html);
            return html;
        }

        let localMap = new Map(), localSkuData = [];
        //多规格参数
        let productSpecValueByProductSpecValueIds = new Map();
        let productSpecValueByProductSpecValueIdsStr = '';

        function createProductSpecValueSku(dbSkuMap) {
            //获取checkbox[name='like']的值
            $("[lay-id=productSkuTable] table").remove();
            var arrProductSpec = new Array();
            var arrProductSpecId = new Array();

            $("input:checkbox[name='productSpec']:checked").each(function (i) {

                arrProductSpec[i] = $(this).attr('title');
                arrProductSpecId[i] = $(this).val();

            });

            $("input:checkbox[lay-filter='productSpecValue']:checked").each(function (i) {
                productSpecValueByProductSpecValueIdsStr += $(this).val() + "_"
            });

            if (productSpecValueByProductSpecValueIdsStr.length > 0) {
                productSpecValueByProductSpecValueIdsStr = productSpecValueByProductSpecValueIdsStr.substring(0, productSpecValueByProductSpecValueIdsStr.length - 1);
                // 请求多规格参数
                admin.req('enterprise/product/admin/productSpecValue/getProductSpecValueByProductSpecValueIds', {productSpecValueIds: productSpecValueByProductSpecValueIdsStr}, res => {
                    if (res.code === 200) {
                        res.data.forEach(item => {
                            productSpecValueByProductSpecValueIds.set(item.id, item)
                        });
                    }
                }, 'get', false);
            }


            // console.log(arrProductSpec);
            //console.log(arrProductSpecId);
            let headData = [];
            let skuData = [];
            headData.push({align: 'center', toolbar: '#skuTableBar', title: '操作', width: 100});
            headData.push({field: 'id', title: '序号', width: 80});
            headData.push({field: 'skuName', sort: true, title: '物料名称'});
            headData.push({field: 'skuCode', sort: true, title: '物料编号'});
            //headData.push({field: 'productPic', sort: true, title: 'SKU图片'})
            var skus = [];
            var celNames = [];
            var prefix = "CELL";
            for (var j = 0; j < arrProductSpecId.length; j++) {
                //var arrProductSpecValue = new Array();
                //var arrProductSpecValueId = new Array();

                // headData.push({field: prefix + "_" + j, sort: true, title: '' + arrProductSpec[j] + ''})
                celNames.push(prefix + "_" + j)

                var sku = [];
                $("input:checkbox[name='productSpecValue" + arrProductSpecId[j] + "']:checked").each(function (i) {
                    //arrProductSpecValue[i] = $(this).attr('title');
                    //arrProductSpecValueId[i] = $(this).val();
                    //物料规格和物料规格的值都需要传到后台数据库进行保存
                    sku.push($(this).attr('title') + ":" + arrProductSpecId[j] + ":" + $(this).val())
                });
                skus.push(sku);
            }
            var productSkus = createSku(skus);
            var newCreateSkuMap = new Map();
            if (productSkus) {
                productSkus.forEach(item => {
                    if (dbSkuMap) {
                        //60MM:2:5_白色:1:1
                        var array = item.split("_");
                        var temp = '';
                        for (var i = 0; i < array.length; i++) {
                            var array2 = array[i].split(":");
                            temp += array2[2] + "_";
                        }
                        temp = temp.substring(0, temp.length - 1);
                        var dbSku = dbSkuMap.get(temp);
                        if (dbSku) {
                            newCreateSkuMap.set(temp, dbSku);
                            localMap.set(temp, dbSku)
                        }
                    }
                })
            }
            headData.push({
                field: 'skuSpecValueNames',
                title: '规格码',
                templet: d => {
                    let arraySplicing = '';
                    let arraySplicingArray = [];
                    arraySplicingArray = $(d.skuName).eq(1).val().split('_');
                    for (let i = 0; i < arraySplicingArray.length; i++) {
                        if (productSpecValueByProductSpecValueIds.has(arraySplicingArray[i])) {
                            if (productSpecValueByProductSpecValueIds.get(arraySplicingArray[i]).specCode == '0') {
                                var specName = productSpecValueByProductSpecValueIds.get(arraySplicingArray[i]).value;
                                if (productSpecValueByProductSpecValueIds.get(arraySplicingArray[i]).specLocation == '0') {
                                    // beforeStr = productSpecValueByProductSpecValueIds.get(arraySplicingArray[i]).specHead;
                                    arraySplicing += productSpecValueByProductSpecValueIds.get(arraySplicingArray[i]).specHead + specName + "-";
                                } else if (productSpecValueByProductSpecValueIds.get(arraySplicingArray[i]).specLocation == '1') {
                                    // lastStr = productSpecValueByProductSpecValueIds.get(arraySplicingArray[i]).specHead;
                                    arraySplicing += specName + productSpecValueByProductSpecValueIds.get(arraySplicingArray[i]).specHead + "-";
                                }
                            }
                        }
                    }

                    return "<span name='skuSpecValueNamesSpan'>" + arraySplicing.substring(0, arraySplicing.length - 1) + "</span>"
                }
            });
            if (null == productSkus || "" == productSkus) {
                // layer.msg("物料规格值为空,请先前往配置物料规格值！", {icon: 2});
                return;
            }
            //var aa = eval("(" + productSkus + ")");
            //console.log(productSkus.length);
            var count = 1;

            for (var i = 0; i < productSkus.length; i++) {
                var celStr = {};
                var sukArray = productSkus[i].split("_");
                celStr["id"] = count;
                let skuSpec = '';
                let skuSpecValue = '';
                let skuSpecValueNames = '';
                for (var j = 0; j < sukArray.length; j++) {
                    var idArray = sukArray[j].split(":");
                    //['50MM:1:4', '白色:1:1']
                    // console.log(sukArray);
                    celStr[celNames[j]] = idArray[0];
                    skuSpec += idArray[1] + "_";
                    skuSpecValue += idArray[2] + "_";
                    skuSpecValueNames += idArray[0] + "_";
                }

                skuSpec = skuSpec.substring(0, skuSpec.length - 1);
                skuSpecValue = skuSpecValue.substring(0, skuSpecValue.length - 1);
                skuSpecValueNames = skuSpecValueNames.substring(0, skuSpecValueNames.length - 1);
                celStr["skuName"] = '<input type="hidden" name="skuSpec" value="' + skuSpec + '" ><input type="hidden" name="skuSpecValue" value="' + skuSpecValue + '" ><input type="text" name="skuName" id="skuName' + skuSpecValue + '" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input"><input type="hidden" name="skuSpecValueNames" value="' + skuSpecValueNames + '" >'
                celStr["skuCode"] = '<input type="text" name="skuCode" id="skuCode' + skuSpecValue + '" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">'
                //celStr["productPic"] = '<div id="btnUpload14" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传图片</div><div id="btnUpload14_path" style="margin-left: 260px;line-height: 40px;"></div>'
                celStr["spPrice"] = '<input type="text" name="spPrice" id="spPrice' + skuSpecValue + '" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">';
                celStr["marketPrice"] = '<input type="text" name="marketPrice" id="marketPrice' + skuSpecValue + '" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">';
                celStr["supplyPrice"] = '<input type="text" name="supplyPrice" id="supplyPrice' + skuSpecValue + '" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">';
                celStr["activityPrice"] = '<input type="text" name="activityPrice" id="activityPrice' + skuSpecValue + '" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">';
                celStr["enterpriceCode"] = '<input type="text" name="enterpriceCode" id="enterpriceCode' + skuSpecValue + '" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">';
                celStr["barcode"] = '<input type="text" name="barcode" id="barcode' + skuSpecValue + '" required  lay-verify="required" placeholder="" autocomplete="off" class="layui-input"><input type="hidden" name="skuId" id="skuId' + skuSpecValue + '" value="" >';
                celStr["oldSpecCode"] = '<input type="text" name="oldSpecCode" id="oldSpecCode' + skuSpecValue + '"  lay-verify="required"  autocomplete="off" class="layui-input" value="" >';
                skuData.push(celStr)
                count++;
            }

            headData.push({field: 'spPrice', sort: true, title: '渠道价'});
            headData.push({field: 'marketPrice', sort: true, title: '市场价'});
            headData.push({field: 'supplyPrice', sort: true, title: '平台供货价'});
            headData.push({field: 'activityPrice', sort: true, title: '最低活动价'});
            headData.push({field: 'enterpriceCode', sort: true, title: '商品货号'});
            headData.push({field: 'barcode', sort: true, title: '商品条形码'});
            headData.push({field: 'oldSpecCode', title: '旧规格码'});

            skuData.forEach((item, index) => {
                item.isShow = false;
            localSkuData.forEach((item1, index1) => {
                if (item.skuName == item1.skuName) {
                item.isShow = item1.isShow;
            }
        })
        });

            localSkuData.forEach((item, index) => {
                if (localMap.has($(item.skuName).eq(1)[0].value)) {
                item.isShow = true;
            }
        });


            var itb = table.render({
                elem: '#productSkuTable',
                data: skuData,
                page: false,
                limit: Number.MAX_VALUE,
                cellMinWidth: 150,
                height: 500,
                cols: [headData],
                done: function (res, curr, count) {
                    res.data.forEach(item => {
                        if (item.isShow == false) {
                            $("#" + $(item.skuName).eq(2)[0].id).parents('tr').find('td:not(:first-child)').css({
                                cursor: 'not-allowed',
                                backgroundColor: '#cfcfcf'
                            });
                            $("#" + $(item.skuName).eq(2)[0].id).parents('tr').find('input').css({
                                cursor: 'not-allowed',
                                backgroundColor: '#cfcfcf'
                            });
                            $("#" + $(item.skuName).eq(2)[0].id).parents('tr').find('input').attr('disabled', 'disabled');
                            $("#" + $(item.skuName).eq(2)[0].id).parents('tr').find('input').removeAttr('lay-verify');
                        } else {
                            $("#" + $(item.skuName).eq(2)[0].id).parents('tr').find('td:not(:first-child)').css({
                                cursor: 'auto',
                                backgroundColor: 'none'
                            });
                            $("#" + $(item.skuName).eq(2)[0].id).parents('tr').find('input').css({
                                cursor: 'auto',
                                backgroundColor: 'none'
                            });
                            $("#" + $(item.skuName).eq(2)[0].id).parents('tr').find('input').removeAttr('disabled');
                            $("#" + $(item.skuName).eq(2)[0].id).parents('tr').find('input[type="text"]').attr('lay-verify', "required");
                        }
                    });

                    if (localMap) {
                        localMap.forEach(item => {
                            var specKey = item.skuSpecValue;
                            $("#skuName" + specKey).val(item.skuName);
                            $("#skuCode" + specKey).val(item.skuCode);
                            $("#spPrice" + specKey).val(item.spPrice);
                            $("#marketPrice" + specKey).val(item.marketPrice);
                            $("#supplyPrice" + specKey).val(item.supplyPrice);
                            $("#activityPrice" + specKey).val(item.activityPrice);
                            $("#enterpriceCode" + specKey).val(item.enterpriceCode);
                            $("#barcode" + specKey).val(item.barcode);
                            $("#skuId" + specKey).val(item.id);
                            $("#oldSpecCode" + specKey).val(item.oldSpecCode);

                            form.render();
                        })
                    }
                }
            });

            if (newCreateSkuMap.size > 0) {
                newCreateSkuMap.forEach(item => {
                    if (localMap.has(item.skuSpecValue)) {
                        let localMapVlue = Object.assign(newCreateSkuMap.get(item.skuSpecValue), item);
                        localMap.set(item.skuSpecValue, localMapVlue)
                    } else {
                        localMap.set(item.skuSpecValue, item)
                    }
                });
            }

            let localMapObj = {};

            $("body").delegate("input[name='skuName']", "change", function () {
                if (skuData[$(this).parents('tr').index()]) {
                    localMapObj = {};
                    localMapObj.skuName = $(this).val();
                    localMapObj.skuSpecValue = $(this).prev().val();
                    console.log(localMap)
                    storageLocaData($(this), localMapObj);
                }
            });

            $("body").delegate("input[name='skuCode']", "change", function () {
                if (skuData[$(this).parents('tr').index()]) {
                    localMapObj = {};
                    localMapObj.skuCode = $(this).val();
                    storageLocaData($(this), localMapObj);
                }
            });
            $("body").delegate("input[name='oldSpecCode']", "change", function () {
                if (skuData[$(this).parents('tr').index()]) {
                    localMapObj = {};
                    localMapObj.oldSpecCode = $(this).val();
                    storageLocaData($(this), localMapObj);
                }
            });

            $("body").delegate("input[name='spPrice']", "change", function () {
                if (skuData[$(this).parents('tr').index()]) {
                    localMapObj = {};
                    localMapObj.spPrice = $(this).val();
                    storageLocaData($(this), localMapObj);
                }
            });

            $("body").delegate("input[name='marketPrice']", "change", function () {
                if (skuData[$(this).parents('tr').index()]) {
                    localMapObj = {};
                    localMapObj.marketPrice = $(this).val();
                    storageLocaData($(this), localMapObj);
                }
            });

            $("body").delegate("input[name='supplyPrice']", "change", function () {
                if (skuData[$(this).parents('tr').index()]) {
                    localMapObj = {};
                    localMapObj.supplyPrice = $(this).val();
                    storageLocaData($(this), localMapObj);
                }
            });

            $("body").delegate("input[name='activityPrice']", "change", function () {
                if (skuData[$(this).parents('tr').index()]) {
                    localMapObj = {};
                    localMapObj.activityPrice = $(this).val();
                    storageLocaData($(this), localMapObj);
                }
            });

            $("body").delegate("input[name='enterpriceCode']", "change", function () {
                if (skuData[$(this).parents('tr').index()]) {
                    localMapObj = {};
                    localMapObj.enterpriceCode = $(this).val();
                    storageLocaData($(this), localMapObj);
                }
            });
            $("body").delegate("input[name='barcode']", "change", function () {
                if (skuData[$(this).parents('tr').index()]) {
                    localMapObj = {};
                    localMapObj.barcode = $(this).val();
                    storageLocaData($(this), localMapObj);
                }
            });

            // 工具条点击事件
            table.on('tool(productSkuTable)', function (obj) {
                var data = obj.data;
                if (obj.event === 'delete') { // 删除
                    layer.confirm("确定删除吗？", {}, function (i) {
                        layer.close(i);
                        //从表格数据中删除
                        skuData = skuData.filter(item => {
                            if (item.id == obj.data.id) {
                                return false;
                            }
                            return true;
                        });
                        itb.reload({data: skuData});
                        if (newCreateSkuMap) {
                            newCreateSkuMap.forEach(item => {
                                console.log(item);
                                var specKey = item.skuSpecValue;
                                $("#skuName" + specKey).val(item.skuName);
                                $("#skuCode" + specKey).val(item.skuCode);
                                $("#spPrice" + specKey).val(item.spPrice);
                                $("#marketPrice" + specKey).val(item.marketPrice);
                                $("#supplyPrice" + specKey).val(item.supplyPrice);
                                $("#activityPrice" + specKey).val(item.activityPrice);
                                $("#enterpriceCode" + specKey).val(item.enterpriceCode);
                                $("#barcode" + specKey).val(item.barcode);
                                $("#skuId" + specKey).val(item.id);
                            })
                        }
                    });
                } else if (obj.event === 'frozen') {
                    localSkuData.forEach((item, index) => {
                        if (item.skuName === data.skuName) {
                            item.isShow = false;
                        }
                    });

                    skuData.forEach(item => {
                        if (item.skuName === data.skuName) {
                            item.isShow = false;
                        }

                    });
                    itb.reload({data: skuData});
                } else if (obj.event === 'thaw') {
                    localSkuData.forEach(item => {
                        if (item.skuName === data.skuName) {
                            item.isShow = true;
                        }
                    });

                    skuData.forEach(item => {
                        if (item.skuName === data.skuName) {
                            item.isShow = true;
                        }
                    });
                    itb.reload({data: skuData});
                }
            });

            //数据库中如果有记录则回显
            if (newCreateSkuMap) {
                newCreateSkuMap.forEach(item => {
                    console.log(item);
                    var specKey = item.skuSpecValue;
                    $("#skuName" + specKey).val(item.skuName);
                    $("#skuCode" + specKey).val(item.skuCode);
                    $("#spPrice" + specKey).val(item.spPrice);
                    $("#marketPrice" + specKey).val(item.marketPrice);
                    $("#supplyPrice" + specKey).val(item.supplyPrice);
                    $("#activityPrice" + specKey).val(item.activityPrice);
                    $("#enterpriceCode" + specKey).val(item.enterpriceCode);
                    $("#barcode" + specKey).val(item.barcode);
                    $("#skuId" + specKey).val(item.id);
                    $("#oldSpecCode" + specKey).val(item.oldSpecCode);
                    form.render();
                })
            }

        }

        function storageLocaData(ele, _localMapObj) {
            if (!ele || !_localMapObj) {
                return false;
            }
            if (localMap.has(ele.parents('tr').find('input[name="skuSpecValue"]').val())) {
                localMap.set(ele.parents('tr').find('input[name="skuSpecValue"]').val(), Object.assign(localMap.get(ele.parents('tr').find('input[name="skuSpecValue"]').val()), _localMapObj));
            } else {
                localMap.set(ele.parents('tr').find('input[name="skuSpecValue"]').val(), _localMapObj);
            }
        }

        function createSku(datas) {
            //console.log(datas);
            var index = 0;
            var first = datas[index];
            while (index < datas.length) {

                index++;
                if (index >= datas.length) {
                    break;
                }
                var second = datas[index];
                var size = first.length * second.length;
                var temp = [];
                var m = 0;
                for (var i = 0; i < first.length; i++) {
                    for (var j = 0; j < second.length; j++) {
                        temp[m++] = first[i] + "_" + second[j];
                    }
                }
                first = temp;
            }
            //console.log(first);
            return first;
        }

        function createProductSpec(data) {
            $("[lay-id=productSkuTable] table").remove();
            if (null == data.value || "" == data.value) {
                layer.msg("请先选择物料类型！", {icon: 2});
                return;
            }

            $("[name='productSpecHtml']").html("");
            $("[name='productSpecValueHtml']").html("");
            $("[name='productSkuTable']").html("");
            //form.render();
            //console.log(data.value); //得到被选中的值
            //加载商品规格
            admin.req('enterprise/product/admin/productSpec/getProductSpecByProductTypeId', {productTypeId: data.value}, function (res) {
                let html = '';
                var data = res.data;
                if (!data || data == null) {
                    layer.msg("物料类型规格为空,请先前往配置物料规格！", {icon: 2});
                    return;
                }
                for (let i = 0; i < data.length; i++) {
                    html += '<input lay-filter="productSpec" id="productSpec" type="checkbox" name  = "productSpec" value="' + data[i].id + '" lay-skin="primary" title="' + data[i].name + '" >';
                }
                //console.log(html);
                $("[name='productSpecHtml']").html(html);
                form.render();
            }, 'get', false);
            createProductSpecValueSku();
        }

        function createProductAttr(data) {
            let html = '';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                //多选
                if (data[i].style == 'many') {
                    html += '<div style="margin-top: 20px" name="attrValue' + data[i].name + '">';
                    html += '<div class="layui-form-item">';
                    html += '<label class="layui-form-label" style="padding-left: 0;text-align: left;">' + data[i].name + ':</label>';
                    html += '<div class="layui-input-block">';

                    for (let j = 0; j < data[i].productAttributeValue.length; j++) {
                        var subData = data[i].productAttributeValue[j];
                        html += '<input lay-filter="productAttrValue' + data[i].id + '" type="checkbox" name  = "productAttrValue' + data[i].id + '"  value="' + subData.id + '" lay-skin="primary" title="' + subData.value + '">';
                    }
                    html += '</div>';
                    html += '</div>';
                    html += '</div>';
                }
                //单选
                if (data[i].style == 'single') {
                    html += '<div style="margin-top: 20px" name="attrValue' + data[i].name + '">';
                    html += '<div class="layui-form-item">';
                    html += '<label class="layui-form-label" style="padding-left: 0;text-align: left;">' + data[i].name + ':</label>';
                    html += '<div class="layui-input-block">';
                    html += '<select lay-filter="productAttrValue' + data[i].id + '"  name="productAttrValue' + data[i].id + '" id="productAttrValue' + data[i].id + '" lay-verify="required">';
                    html += '<option value="">请选择属性</option>';
                    for (let j = 0; j < data[i].productAttributeValue.length; j++) {
                        var subData = data[i].productAttributeValue[j];
                        html += '<option value="' + subData.id + '">' + subData.value + '</option>';
                    }
                    html += "</select>";
                    html += '</div>';
                    html += '</div>';
                    html += '</div>';
                }
                //文本
                if (data[i].style == 'text') {
                    html += '<div style="margin-top: 20px" name="attrValue' + data[i].name + '">';
                    html += '<div class="layui-form-item">';
                    html += '<label class="layui-form-label" style="padding-left: 0;text-align: left;">' + data[i].name + ':</label>';
                    html += '<div class="layui-input-block">';
                    html += '<input type="text" class="layui-input" lay-filter="productAttrValue' + data[i].id + '" name="productAttrValue' + data[i].id + '" id="productAttrValue' + data[i].id + '" lay-verify="required" />';
                    html += '</div>';
                    html += '</div>';
                    html += '</div>';
                }
            }
            //console.log(html);
            $("[name='productAttrHtml']").html(html);
            form.render();

        }

        //导入excel
        $('#uploaderInput').on("change", function (e) {
            layer.load(2);
            var formData = new FormData();
            var files = e.target.files;
            let that = $(this);
            formData.append("file", files[0]);
            formData.append("name", files[0].name);//这个地方可以传递多个参数
            $.ajax({
                url: config.base + 'enterprisecab/productCab/admin/product/importExcel',
                data: formData,
                headers: {Authorization: 'Bearer ' + config.getToken()},
                type: "POST",
                processData: false,
                contentType: false,
                success: function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        // table.reload('humanResourcesTable');
                        layer.closeAll('page');
                        setTimeout(_ => {
                            location.reload()
                        }, 1000);
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                    that.val('');
                }
            });

        })

        // 模板下载
        $('#fromLocalWarehouseBtnTemplate').click(function () {
            window.location.href = config.base + "enterprisecab/productCab/admin/product/template";
        });

        // 导出
        $('#exportProductBtn').click(function () {
            var sTime = $('#startTime').val();
            var eTime = $('#endTime').val();
            location.href = config.base + 'enterprisecab/productCab/admin/product/export?startCreateTime=' + sTime + '&endCreateTime=' + eTime;
            // location.href = config.base + 'enterprisecab/productCab/admin/product/export?startTime=' + sTime + '&endTime=' + eTime;
        });


        //   新 添加自采商品
        function showAddSelfCollectedGoods(_data) {
            admin.open({
                type: 1,
                area: ["1830px", '800px'],
                offset: '65px',
                title: _data ? '修改自采物料' : '添加自采物料',
                content: $('#addSelfCollectedGoods').html(),
                success: function () {
                    let addSelfCollectedGoodsTableListData = [], specificationCode = [],
                        addSelfCollectedGoodsTableListProductPack = [], addSelfCollectedGoodsTableListProductUnit = [],
                        isBaseUnitProductUnit = '';
                    let getProductInfoBySkuCodeData = '';
                    let cacheParameters = {productTypeId: '', addSelfCollectedGoodsNum: 0}; //保存请求参数,防止同一参数多次请求

                    let selectedData = function (treeData, targetId) {
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    };

                    //请求物料类型
                    admin.reqSync('enterprise/product/admin/productType/getProductTypeByType', {type: '0'}, res => {
                        if (res.code === 200) {
                            loadAddSelfCollectedGoodsSelectHtml(res.data, '请选择类型', 'addSelfCollectedGoodsProductTypeId', 1)
                        }
                    }, 'GET');

                    //请求供应商
                    admin.reqSync('enterprise/purchase/admin/supplierInfoPass/getAll', {}, res => {
                        if (res.code === 200) {
                            loadAddSelfCollectedGoodsSelectHtml(res.data, '请选择供应商', 'supplierId', 2)
                        }else {
                            loadAddSelfCollectedGoodsSelectHtml([], '请选择供应商', 'supplierId', 2)
                        }
                    }, 'GET');


                    //请求品牌
                    admin.reqSync('enterprise/product/admin/productBrand/getAllProductBrandByType', {type: '0'}, res => {
                        if (res.code === 200) {
                            let brandList = []
                            res.data.forEach(item => {
                                if (item.isDeleted) {
                                    brandList.push(item)
                                }
                            })
                            loadAddSelfCollectedGoodsSelectHtml(brandList, '请选择', 'addSelfCollectedGoodsBrandId', 1)
                        }
                    }, 'GET');


                    if (_data) {

                        $('#addSelfCollectedGoodsProductTypeId').attr('disabled', 'disabled');
                        // $('#addSelfCollectedGoodsBrandId').attr('disabled', 'disabled');
                        $('.addSelfCollectedGoodsForm input[name="name"]').attr('disabled', 'disabled');
                        $('.addSelfCollectedGoodsForm input[name="productCode"]').attr('disabled', 'disabled');
                        $('.addSelfCollectedGoodsNumBox').hide();
                        $('.addSelfCollectedGoodsPictureBox').hide();
                        $('.addSelfCollectedGoodsForm select[lay-verify="required"]').removeAttr('lay-verify');
                        $('.addSelfCollectedGoodsForm input[lay-verify="required"]').removeAttr('lay-verify');
                        $('#addSelfCollectedGoodsTableModifyListUploadImg').val(_data.productPic);
                        $('#addSelfCollectedGoodsTableModifyListUploadImg_path').html('<img src="' + _data.productPic + '"/>');

                        //规格数据
                        admin.reqSync('enterprisecab/productCab/admin/productDetail/getProductInfoBySkuCode', {skuCode: _data.skuCode}, function (res) {
                            if (res.code === 200) {
                                getProductInfoBySkuCodeData = res.data;
                                getProductInfoBySkuCodeData.addSelfCollectedGoodsProductTypeId = getProductInfoBySkuCodeData.productTypeId;
                                getProductInfoBySkuCodeData.addSelfCollectedGoodsBrandId = getProductInfoBySkuCodeData.brandId;
                                getProductInfoBySkuCodeData.name = getProductInfoBySkuCodeData.productName;
                                getProductInfoBySkuCodeData.productCode = getProductInfoBySkuCodeData.productCode;

                                getProductInfoBySkuCodeData.inventoryUnitType = _data.inventoryUnitType;
                                getProductInfoBySkuCodeData.storageKnifeType = _data.storageKnifeType;
                                getProductInfoBySkuCodeData.returnType = _data.returnType.toString();
                                getProductInfoBySkuCodeData.warningQuantity = _data.warningQuantity;

                                //规格数据
                                admin.reqSync('enterprise/product/admin/productSpec/getProductSpecByProductTypeId', {productTypeId: getProductInfoBySkuCodeData.addSelfCollectedGoodsProductTypeId}, function (res) {
                                    if (res.code === 200) {
                                        getProductInfoBySkuCodeData.specificationCode = res.data;
                                    }
                                }, 'get');

                                //包装方案
                                admin.reqSync('enterprise/product/admin/productPack/getByProductTypeId', {productTypeId: getProductInfoBySkuCodeData.addSelfCollectedGoodsProductTypeId}, function (res) {
                                    if (res.code === 200) {
                                        getProductInfoBySkuCodeData.addSelfCollectedGoodsTableListProductPack = res.data;
                                    }
                                }, 'get');

                                // 包装单位
                                admin.reqSync('enterprise/product/admin/productUnit/getProductUnitByType', {
                                    type: 0,
                                    productTypeId: getProductInfoBySkuCodeData.addSelfCollectedGoodsProductTypeId
                                }, function (res) {
                                    if (res.code === 200) {
                                        getProductInfoBySkuCodeData.addSelfCollectedGoodsTableListProductUnit = res.data;
                                    }
                                }, 'get');

                                admin.reqSync('enterprise/product/admin/productUnit/getIsBaseUnitProductUnitByType', {
                                    type: 0,
                                    productTypeId: getProductInfoBySkuCodeData.addSelfCollectedGoodsProductTypeId
                                }, res => {
                                    if (res.code === 200) {
                                        getProductInfoBySkuCodeData.isBaseUnitProductUnit = res.data.name || '';
                                    }
                                }, 'get');


                            }
                        }, 'get');


                    } else {
                        $('.addSelfCollectedGoodsTableModifyListUploadImgBox').hide();
                        $('#inventoryUnitTypeBox').remove();
                        $('#returnTypeBox').remove();
                        $('#storageKnifeTypeBox').remove();
                        $('#addSelfCollectedGoodsQuery').click(function () {
                            if ($('#addSelfCollectedGoodsProductTypeId').val() == '') {
                                layer.msg('请选择类型', {icon: '5'})
                            } else if ($('#addSelfCollectedGoodsNum').val() == '') {
                                layer.msg('请选输入规格数', {icon: '5'})
                            } else {
                                layer.load(2);
                                /* if (cacheParameters.productTypeId == $('#addSelfCollectedGoodsProductTypeId').val()) {
                                     if (cacheParameters.addSelfCollectedGoodsNum == $('#addSelfCollectedGoodsNum').val()) {

                                     } else if (cacheParameters.addSelfCollectedGoodsNum > $('#addSelfCollectedGoodsNum').val()) {
                                         addSelfCollectedGoodsTableListData = addSelfCollectedGoodsTableListData.splice(0, $('#addSelfCollectedGoodsNum').val());
                                         cacheParameters.addSelfCollectedGoodsNum = $('#addSelfCollectedGoodsNum').val();

                                     } else {
                                         for (let i = cacheParameters.addSelfCollectedGoodsNum; i < $('#addSelfCollectedGoodsNum').val(); i++) {
                                             addSelfCollectedGoodsTableListData.push({
                                                 index: i,
                                                 isShow: true,
                                                 specificationCode: specificationCode,
                                                 addSelfCollectedGoodsTableListProductPack: addSelfCollectedGoodsTableListProductPack,
                                                 addSelfCollectedGoodsTableListProductUnit: addSelfCollectedGoodsTableListProductUnit,
                                                 isBaseUnitProductUnit: isBaseUnitProductUnit,
                                                 skuCode: '',
                                                 skuName: '',
                                                 oldSkuCode: '',
                                                 oldSpecCode: '',
                                                 marketPrice: '',
                                                 packId: {name: '', id: ''},
                                                 unitId: {name: '', id: ''},
                                                 skuSpecValueNames: []
                                             })
                                         }
                                         cacheParameters.addSelfCollectedGoodsNum = $('#addSelfCollectedGoodsNum').val();

                                     }
                                 } else {
                                     cacheParameters.productTypeId = $('#addSelfCollectedGoodsProductTypeId').val();
                                     cacheParameters.addSelfCollectedGoodsNum = $('#addSelfCollectedGoodsNum').val();
                                     specificationCode = [];
                                     addSelfCollectedGoodsTableListProductPack = [];
                                     addSelfCollectedGoodsTableListData = [];
                                     addSelfCollectedGoodsTableListProductUnit = [];
                                     isBaseUnitProductUnit = '';
                                     //规格数据
                                     admin.reqSync('enterprise/product/admin/productSpec/getProductSpecByProductTypeId', {productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()}, res => {
                                         if (res.code === 200) {
                                             specificationCode = res.data;
                                         }
                                     }, 'get');

                                     //包装方案
                                     admin.reqSync('enterprise/product/admin/productPack/getByProductTypeId', {productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()}, res => {
                                         if (res.code === 200) {
                                             addSelfCollectedGoodsTableListProductPack = res.data;
                                         }
                                     }, 'get');

                                     // 包装单位
                                     admin.reqSync('enterprise/product/admin/productUnit/getProductUnitByType', {
                                         type: 0,
                                         productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()
                                     }, res => {
                                         if (res.code === 200) {
                                             addSelfCollectedGoodsTableListProductUnit = res.data;
                                         }
                                     }, 'get');

                                     //基础单位
                                     admin.reqSync('enterprise/product/admin/productUnit/getIsBaseUnitProductUnitByType', {
                                         type: 0,
                                         productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()
                                     }, res => {
                                         if (res.code === 200) {
                                             isBaseUnitProductUnit = res.data.name || '';
                                         }
                                     }, 'get');

                                     new Promise((resolve, reject) => {
                                         for (let i = 0; i < $('#addSelfCollectedGoodsNum').val(); i++) {
                                             addSelfCollectedGoodsTableListData.push({
                                                 index: i,
                                                 isShow: true,
                                                 specificationCode: specificationCode,
                                                 addSelfCollectedGoodsTableListProductPack: addSelfCollectedGoodsTableListProductPack,
                                                 addSelfCollectedGoodsTableListProductUnit: addSelfCollectedGoodsTableListProductUnit,
                                                 isBaseUnitProductUnit: isBaseUnitProductUnit,
                                                 skuCode: '',
                                                 skuName: '',
                                                 oldSkuCode: '',
                                                 oldSpecCode: '',
                                                 marketPrice: '',
                                                 packId: {name: '', id: ''},
                                                 unitId: {name: '', id: ''},
                                                 skuSpecValueNames: []
                                             })
                                         }
                                         resolve(addSelfCollectedGoodsTableListData);
                                     }).then(r => {
                                         table.reload('addSelfCollectedGoodsTableList', {data: r});
                                     });


                                     console.log(2,addSelfCollectedGoodsTableListData)
                                 }*/

                                cacheParameters.productTypeId = $('#addSelfCollectedGoodsProductTypeId').val();
                                cacheParameters.addSelfCollectedGoodsNum = $('#addSelfCollectedGoodsNum').val();
                                specificationCode = [];
                                addSelfCollectedGoodsTableListProductPack = [];
                                addSelfCollectedGoodsTableListData = [];
                                addSelfCollectedGoodsTableListProductUnit = [];
                                isBaseUnitProductUnit = '';
                                //规格数据
                                admin.reqSync('enterprise/product/admin/productSpec/getProductSpecByProductTypeId', {productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()}, res => {
                                    if (res.code === 200) {
                                        specificationCode = res.data;
                                    }
                                }, 'get');

                                //包装方案
                                admin.reqSync('enterprise/product/admin/productPack/getByProductTypeId', {productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()}, res => {
                                    if (res.code === 200) {
                                        addSelfCollectedGoodsTableListProductPack = res.data;
                                    }
                                }, 'get');

                                // 包装单位
                                admin.reqSync('enterprise/product/admin/productUnit/getProductUnitByType', {
                                    type: 0,
                                    productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()
                                }, res => {
                                    if (res.code === 200) {
                                        addSelfCollectedGoodsTableListProductUnit = res.data;
                                    }
                                }, 'get');

                                //基础单位
                                admin.reqSync('enterprise/product/admin/productUnit/getIsBaseUnitProductUnitByType', {
                                    type: 0,
                                    productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()
                                }, res => {
                                    if (res.code === 200) {
                                        isBaseUnitProductUnit = res.data.name || '';
                                    }
                                }, 'get');

                                new Promise((resolve, reject) => {
                                    for (let i = 0; i < $('#addSelfCollectedGoodsNum').val(); i++) {
                                        addSelfCollectedGoodsTableListData.push({
                                            index: i,
                                            isShow: true,
                                            specificationCode: specificationCode.map(o => Object.assign({}, o)),
                                            addSelfCollectedGoodsTableListProductPack: addSelfCollectedGoodsTableListProductPack,
                                            addSelfCollectedGoodsTableListProductUnit: addSelfCollectedGoodsTableListProductUnit,
                                            isBaseUnitProductUnit: isBaseUnitProductUnit,
                                            skuCode: '',
                                            skuName: '',
                                            oldSkuCode: '',
                                            oldSpecCode: '',
                                            marketPrice: '',
                                            packId: {name: '', id: ''},
                                            unitId: {name: '', id: ''},
                                            lifeUnit: {name: '', id: ''},
                                            lifeSpan: '',
                                            skuSpecValueNames: []
                                        })
                                    }
                                    resolve(addSelfCollectedGoodsTableListData);
                                }).then(r => {
                                    table.reload('addSelfCollectedGoodsTableList', {data: r});
                                });
                                layer.closeAll('loading');
                            }

                        });
                        $('#addSelfCollectedGoodsPictureBtn').click(uploadImg('addSelfCollectedGoodsPictureBtn', 'addSelfCollectedGoodsPicture_path', 'addSelfCollectedGoodsPicture'));
                    }


                    // 请求物料分类
                    let arr2tree;
                    admin.reqSync('enterprise/product/admin/productCategory/getProductCategoryByType', {type: 0}, function (res) {
                        let categoryList = []
                        for (let i = 0; i < res.data.length; i++) {
                            if (res.data[i].isDeleted) {
                                res.data[i].children = [];
                                categoryList.push(res.data[i])
                            }
                        }
                        arr2tree = xmSelect.arr2tree(categoryList, "parentId", "id", "children", -1);
                    }, 'get', false);
                    selectedData(arr2tree, getProductInfoBySkuCodeData.productCategoryId);

                    let smlSelectInstans = xmSelect.render({
                        el: '#addSelfCollectedGoodsProductCategoryId',
                        model: {label: {type: 'text'}},
                        radio: true,
                        clickClose: true,
                        filterable: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2tree;
                        },
                        on(data) {
                            let parentId = data.arr.length > 0 ? data.change[0].id : -1;
                            $("input[name='addSelfCollectedGoodsProductCategoryId']").val(parentId);
                        }
                    });


                    if (_data) {
                        form.val('addSelfCollectedGoodsForm', getProductInfoBySkuCodeData);
                        let addSelfCollectedGoodsTbModifyList = table.render({
                            elem: '#addSelfCollectedGoodsTableModifyList',
                            page: false,
                            cellMinWidth: 115,
                            data: [getProductInfoBySkuCodeData],
                            cols: [[
                                {
                                    field: 'skuName',
                                    title: '物料名称',
                                    templet: d => '<input type="text" name="skuName" class="layui-input" lay-verify="required" value="' + d.skuName + '">'
                                },
                                {field: 'skuCode', title: '物料编号(唯一)'},
                                {
                                    field: 'skuSpecValueNames', title: '规格码', width: '550', templet: d => {
                                        let selectHTML = '', selectArray = d.skuSpecValue.split("_"), lastValue = '',
                                            beforeValue = '';
                                        d.specificationCode.forEach((item, index) => {
                                            selectHTML += '<div class="skuSpecValueNames" style="width: 130px;float: left;margin-right: 5px;margin-top: 5px;" ><select name="' + d.index + '-' + item.id + '" id="' + d.index + '-' + item.id + '">';
                                            selectHTML += '<option value="">' + item.name + '</option>';
                                            lastValue = '';
                                            beforeValue = '';
                                            if (item.specCode == 'is') {
                                                if (item.specLocation == 'last') {
                                                    lastValue = item.specHead

                                                } else if (item.specLocation == 'before') {
                                                    beforeValue = item.specHead
                                                }
                                            }
                                            item.productSpecValueList.forEach(itemList => {
                                                if (selectArray[index] == itemList.id) {
                                                    selectHTML += '<option value="' + itemList.id + '" skuSpec="' + item.id + '" selected="">' + beforeValue + itemList.value + lastValue + '</option>'
                                                } else {
                                                    selectHTML += '<option value="' + itemList.id + '" skuSpec="' + item.id + '" >' + beforeValue + itemList.value + lastValue + '</option>'
                                                }
                                            });

                                            selectHTML += '</select></div>';

                                        });
                                        return selectHTML;
                                    }
                                },
                                {
                                    field: 'oldSkuCode',
                                    title: '旧物料编号',
                                    templet: d => '<input type="text" name="oldSkuCode" class="layui-input" value="' + d.oldSkuCode + '">'
                                },
                                {
                                    field: 'oldSpecCode',
                                    title: '旧SKU规格码',
                                    templet: d => '<input type="text" name="oldSpecCode" class="layui-input" lay-verify="required" value="' + d.oldSpecCode + '">'
                                },
                                {
                                    field: 'unitId', title: '单位', templet: d => {
                                        let selectHTML = '';
                                        selectHTML += '<select name="unitId">';
                                        selectHTML += '<option value="">包装单位</option>';
                                        d.addSelfCollectedGoodsTableListProductUnit.forEach(item => {
                                            if (d.unitId == item.id) {
                                                selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                            } else {
                                                selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';
                                            }

                                        });
                                        selectHTML += '</select>';
                                        return selectHTML
                                    }
                                },
                                {field: 'isBaseUnitProductUnit', title: '计量单位'},
                                {
                                    field: 'marketPrice',
                                    title: '单价',
                                    templet: d => '<input type="text" name="marketPrice" class="layui-input" lay-verify="" value="' + d.marketPrice + '">'
                                },

                                {
                                    field: 'packId', title: '包装方案', templet: d => {
                                        let selectHTML = '';
                                        selectHTML += '<select name="packId" lay-filter="packId">';
                                        selectHTML += '<option value="">包装方案</option>';
                                        d.addSelfCollectedGoodsTableListProductPack.forEach(item => {
                                            if (d.packId == item.id) {
                                                selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                            } else {
                                                selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';

                                            }
                                        });
                                        selectHTML += '</select>';

                                        return selectHTML
                                    }
                                },
                                {
                                    field: 'lifeUnit',
                                    title: '寿命单位', templet: d => {
                                        let selectHTML = ``;
                                        selectHTML += `<div><select name="lifeUnit">`;
                                        selectHTML += '<option value="">寿命单位</option>';
                                        selectHTML += `<option value="minute" ${d.lifeUnit == 'minute' ? 'selected=""' : ""}>分钟数</option>`;
                                        selectHTML += `<option value="number" ${d.lifeUnit == 'number' ? 'selected=""' : ""}>个数</option>`;
                                        selectHTML += '</select></div>';
                                        return selectHTML;
                                    }
                                },
                                {
                                    field: 'lifeSpan',
                                    title: '使用寿命',
                                    templet: d => '<input type="text" name="lifeSpan" class="layui-input" lay-verify="" value="' + d.lifeSpan + '">'
                                },
                            ]]
                        });

                        $('#addSelfCollectedGoodsTableModifyListUploadImgBtn').click(uploadImg('addSelfCollectedGoodsTableModifyListUploadImgBtn', 'addSelfCollectedGoodsTableModifyListUploadImg_path', 'addSelfCollectedGoodsTableModifyListUploadImg'));
                        form.on('submit(addSelfCollectedGoodsSubmit)', d => {
                            let rowModify = $("[lay-id=addSelfCollectedGoodsTableModifyList] table tbody tr").eq(0);
                            let skuString = '', skuSpecValueString = '', skuSpecString = '',
                                addSelfCollectedGoodsTableModifyListData = {};
                            for (let j = 0; j < rowModify.find('.skuSpecValueNames select').length; j++) {
                                if (rowModify.find(".skuSpecValueNames input").eq(j).val() == '') {
                                    skuString = '';
                                    skuSpecValueString = '';
                                    skuSpecString = '';
                                } else {
                                    skuString += rowModify.find(".skuSpecValueNames input").eq(j).val() + '-';
                                    skuSpecValueString += rowModify.find(".skuSpecValueNames option:selected").eq(j).val() + '_';
                                    skuSpecString += rowModify.find(".skuSpecValueNames option:selected").eq(j).attr('skuspec') + '_';
                                }

                            }


                            addSelfCollectedGoodsTableModifyListData.id = getProductInfoBySkuCodeData.id;
                            addSelfCollectedGoodsTableModifyListData.skuName = rowModify.find('input[name="skuName"]').val();
                            addSelfCollectedGoodsTableModifyListData.oldSkuCode = rowModify.find('input[name="oldSkuCode"]').val();
                            addSelfCollectedGoodsTableModifyListData.oldSpecCode = rowModify.find('input[name="oldSpecCode"]').val();
                            addSelfCollectedGoodsTableModifyListData.marketPrice = rowModify.find('input[name="marketPrice"]').val();
                            addSelfCollectedGoodsTableModifyListData.packId = rowModify.find('select[name="packId"]').val();
                            addSelfCollectedGoodsTableModifyListData.unitId = rowModify.find('select[name="unitId"]').val();
                            addSelfCollectedGoodsTableModifyListData.skuSpecValueNames = skuString.substring(0, skuString.length - 1);
                            addSelfCollectedGoodsTableModifyListData.skuSpecValue = skuSpecValueString.substring(0, skuSpecValueString.length - 1);
                            addSelfCollectedGoodsTableModifyListData.skuSpec = skuSpecString.substring(0, skuSpecString.length - 1);
                            addSelfCollectedGoodsTableModifyListData.productPic = $('#addSelfCollectedGoodsTableModifyListUploadImg').val();

                            addSelfCollectedGoodsTableModifyListData.lifeUnit = rowModify.find('select[name="lifeUnit"]').val();

                            addSelfCollectedGoodsTableModifyListData.lifeSpan = rowModify.find('input[name="lifeSpan"]').val();
                            addSelfCollectedGoodsTableModifyListData.brandId = d.field.addSelfCollectedGoodsBrandId; // 品牌id

                            addSelfCollectedGoodsTableModifyListData.returnThreshold = d.field.returnThreshold; // 归还时长闻值
                            addSelfCollectedGoodsTableModifyListData.lethargyThreshold = d.field.lethargyThreshold; // 呆滞时长闽值

                            addSelfCollectedGoodsTableModifyListData.inventoryUnitType = d.field.inventoryUnitType;
                            addSelfCollectedGoodsTableModifyListData.returnType = d.field.returnType;
                            addSelfCollectedGoodsTableModifyListData.storageKnifeType = d.field.storageKnifeType;
                            addSelfCollectedGoodsTableModifyListData.warningQuantity = d.field.warningQuantity;
                            addSelfCollectedGoodsTableModifyListData.supplierId = d.field.supplierId;


                            layer.load(2);
                            admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/updateProductDetailById', JSON.stringify(addSelfCollectedGoodsTableModifyListData), res => {
                                layer.closeAll('loading');
                                if (res.code === 200) {
                                    layer.closeAll();
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('commonToolCabinetTable');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'put', true, 'application/json; charset=utf-8')
                        });

                    } else {
                        $('#returnThresholdBox').remove();
                        $('#lethargyThresholdBox').remove();
                        let addSelfCollectedGoodsTbList = table.render({
                            elem: '#addSelfCollectedGoodsTableList',
                            page: false,
                            cellMinWidth: 110,
                            data: addSelfCollectedGoodsTableListData,
                            limit: Number.MAX_VALUE,
                            height: 480,
                            cols: [[
                                {type: 'numbers', title: '序号'}
                                , {
                                    field: '', title: '物料名称', templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'} name="skuName" value="${d.skuName}">`
                                    }
                                }
                                , {
                                    field: '',
                                    title: '物料编号(唯一)',
                                    templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'} name="skuCode" value="${d.skuCode}">
                                                <input type="hidden" name="isShow" value="${d.isShow}">`
                                    }
                                }
                                , {
                                    field: '', title: 'SKU规格码', width: '550', templet: d => {
                                        let selectHTML = '', skuSpecValueNamesValue = '', skuSpecValueNamesString = '';
                                        d.skuSpecValueNames.forEach(item => skuSpecValueNamesString += item.name + '-');
                                        selectHTML += `<span style="display:${d.isShow == true ? 'none' : ''}">${skuSpecValueNamesString.substring(0, skuSpecValueNamesString.length - 1)}</span>`;

                                        d.specificationCode.forEach((item, index) => {
                                            let skuSpecValueNamesValueSelect = '';
                                            selectHTML += `<div class="skuSpecValueNames" style="width: 130px;float: left;margin:5px 5px 0 0; display:${d.isShow == true ? '' : 'none'}">
                                                       <select class="skuSpecValueNamesList"  name="${d.index + '-' + item.id}" id="${d.index + '-' + item.id}" style="margin-bottom: 5px" lay-search="">`;
                                            selectHTML += '<option value="">' + item.name + '</option>';
                                            if (d.skuSpecValueNames[index]) {
                                                skuSpecValueNamesValue = d.skuSpecValueNames[index].value;
                                            } else {
                                                skuSpecValueNamesValue = '';
                                            }
                                            item.productSpecValueList.forEach(itemList => {
                                                if (skuSpecValueNamesValue == itemList.id) {
                                                    skuSpecValueNamesValueSelect = 'selected=""'
                                                } else {
                                                    skuSpecValueNamesValueSelect = ''
                                                }
                                                if (item.specCode == 'is') {
                                                    if (item.specLocation == 'last') {
                                                        selectHTML += '<option ' + skuSpecValueNamesValueSelect + ' value="' + itemList.id + '" skuSpec="' + item.id + '" >' + itemList.value + item.specHead + '</option>'
                                                    } else {
                                                        selectHTML += '<option ' + skuSpecValueNamesValueSelect + ' value="' + itemList.id + '" skuSpec="' + item.id + '" >' + item.specHead + itemList.value + '</option>'
                                                    }

                                                } else {
                                                    selectHTML += '<option ' + skuSpecValueNamesValueSelect + ' value="' + itemList.id + '" skuSpec="' + item.id + '" >' + itemList.value + '</option>'
                                                }
                                            });

                                            selectHTML += '</select></div>';

                                        });
                                        return selectHTML;
                                    }
                                }
                                , {
                                    field: '', title: '旧物料编号', templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'} name="oldSkuCode" value="${d.oldSkuCode}">`

                                    }
                                }
                                , {
                                    field: '', title: '旧SKU规格码', templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'} name="oldSpecCode" value="${d.oldSpecCode}">`
                                    }
                                }
                                , {
                                    field: '', title: '单位', templet: d => {
                                        let selectHTML = `<span style="display:${d.isShow == true ? 'none' : ''}">${d.unitId.name}</span>`;
                                        selectHTML += `<div style="display:${d.isShow == true ? '' : 'none'}"><select name="unitId">`;
                                        // selectHTML += '<option value="">包装单位</option>';
                                        d.addSelfCollectedGoodsTableListProductUnit.forEach(item => {
                                            if (d.unitId.value && d.unitId.value == item.id) {
                                                selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                            } else {
                                                selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';
                                            }

                                        });
                                        selectHTML += '</select></div>';
                                        return selectHTML;
                                    }
                                }
                                , {
                                    field: '',
                                    title: '计量单位',
                                    width: '100',
                                    align: 'center',
                                    templet: d => d.isBaseUnitProductUnit
                                }
                                , {
                                    field: '', title: '单价', templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'}
                                                name="marketPrice" value="${d.marketPrice}" onkeyup="value=value.replace(/^\\D*(\\d*(?:\\.\\d{0,2})?).*$/g, \'$1\')">`
                                    }
                                }
                                , {
                                    field: '', title: '包装方案', templet: d => {
                                        let selectHTML = `<span style="display:${d.isShow == true ? 'none' : ''}">${d.packId.name}</span>`;
                                        selectHTML += `<div style="display:${d.isShow == true ? '' : 'none'}"><select name="packId">`;
                                        selectHTML += '<option value="">包装方案</option>';
                                        d.addSelfCollectedGoodsTableListProductPack.forEach(item => {
                                            if (d.packId.value && d.packId.value == item.id) {
                                                selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                            } else {
                                                selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';
                                            }
                                        });
                                        selectHTML += '</select></div>';
                                        return selectHTML;
                                    }
                                },
                                {
                                    field: '',
                                    title: '寿命单位', templet: d => {
                                        let selectHTML = `<span style="display:${d.isShow == true ? 'none' : ''}">${d.lifeUnit.name}</span>`;
                                        selectHTML += `<div style="display:${d.isShow == true ? '' : 'none'}"><select name="lifeUnit">`;
                                        selectHTML += '<option value="">寿命单位</option>';


                                        selectHTML += `<option value="1" ${d.lifeUnit.value == 1 ? 'selected=""' : ""}>分钟数</option>`;
                                        selectHTML += `<option value="2" ${d.lifeUnit.value == 2 ? 'selected=""' : ""}>个数</option>`;
                                        selectHTML += '</select></div>';
                                        return selectHTML;
                                    }
                                },
                                {
                                    field: '',
                                    title: '使用寿命',
                                    templet: d => {
                                        return `<input type="text" class="layui-input ${d.isShow == true ? '' : 'inputBorderNone'}" ${d.isShow == true ? '' : 'readonly'} name="lifeSpan" value="${d.lifeSpan}">`
                                        /*'<input type="text" name="lifeSpan" class="layui-input" lay-verify="" value="">'*/
                                    }
                                },
                                {field: '', title: '操作', templet: '#addSelfCollectedGoodsTableListBar', width: '45'}

                            ]],
                            done: function (res, curr, count) {
                                if (res.data.length > 0) {
                                    res.data.forEach((item, index) => {
                                        if (item.addSelfCollectedGoodsTableListProductUnit.length > 0) {
                                            if (item.addSelfCollectedGoodsTableListProductUnit[0].name === undefined) {
                                                addSelfCollectedGoodsTableListData[index].unitId = {
                                                    name: item.addSelfCollectedGoodsTableListProductUnit[0].name,
                                                    value: item.addSelfCollectedGoodsTableListProductUnit[0].id
                                                }
                                            }
                                        }
                                    })
                                }
                                form.render('select');

                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='skuCode']", "change", function () {
                                    if (addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].skuCode = $(this).val().trim();
                                    }
                                });
                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='skuName']", "change", function () {
                                    if (addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].skuName = $(this).val().trim();
                                    }
                                });
                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='oldSkuCode']", "change", function () {
                                    if (addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].oldSkuCode = $(this).val().trim();
                                    }
                                });
                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='oldSpecCode']", "change", function () {
                                    if (addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].oldSpecCode = $(this).val().trim();
                                    }

                                });
                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='marketPrice']", "change", function () {
                                    if (addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].marketPrice = $(this).val().trim();
                                    }
                                });
                                $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] input[name='lifeSpan']", "change", function () {
                                    if (addSelfCollectedGoodsTableListData[$(this).parents('tr').index()]) {
                                        addSelfCollectedGoodsTableListData[$(this).parents('tr').index()].lifeSpan = $(this).val().trim();
                                    }

                                });
                            }

                        });

                        // sku规格码 动态添加
                        $("body").delegate("[lay-id='addSelfCollectedGoodsTableList'] .skuSpecValueNames input.layui-input", "change", function () {
                            let that = $(this), thisValue = $(this).val().trim(), flag = false, specHead = '',
                                specLocation = '';
                            if ($(this).val().trim() == '') {
                                return false;
                            }
                            if (addSelfCollectedGoodsTableListData[that.parents('tr').index()].specificationCode[that.parents('.skuSpecValueNames').index() - 1].specCode == 'is') {
                                specLocation = addSelfCollectedGoodsTableListData[that.parents('tr').index()].specificationCode[that.parents('.skuSpecValueNames').index() - 1].specLocation;
                                specHead = addSelfCollectedGoodsTableListData[that.parents('tr').index()].specificationCode[that.parents('.skuSpecValueNames').index() - 1].specHead;
                            } else {
                                specHead = '';
                                specLocation = '';
                            }

                            addSelfCollectedGoodsTableListData[that.parents('tr').index()].skuSpecValueNames[that.parents('.skuSpecValueNames').index() - 1] = {
                                name: specLocation == 'before' ? specHead + thisValue : thisValue + specHead,
                                text: thisValue,
                                value: that.parents('tr').index() + 'ydzz2022',
                                parentId: addSelfCollectedGoodsTableListData[that.parents('tr').index()].specificationCode[that.parents('.skuSpecValueNames').index() - 1].id
                            };

                            addSelfCollectedGoodsTableListData[that.parents('tr').index()].specificationCode[that.parents('.skuSpecValueNames').index() - 1].productSpecValueList.forEach(item => {
                                if (item.id.indexOf(that.parents('tr').index() + 'ydzz2022') > -1) {
                                    flag = true;
                                }
                            });

                            if (flag) {
                                addSelfCollectedGoodsTableListData[that.parents('tr').index()].specificationCode[that.parents('.skuSpecValueNames').index() - 1].productSpecValueList.forEach(item => {
                                    if (item.id === that.parents('tr').index() + 'ydzz2022') {
                                        item.value = thisValue;
                                    }
                                })
                            } else {
                                let newData = JSON.stringify(addSelfCollectedGoodsTableListData[that.parents('tr').index()].specificationCode[that.parents('.skuSpecValueNames').index() - 1].productSpecValueList)
                                let newData2 = JSON.parse(newData);
                                newData2.push({
                                    value: thisValue,
                                    id: that.parents('tr').index() + 'ydzz2022',
                                    parentId: addSelfCollectedGoodsTableListData[that.parents('tr').index()].specificationCode[that.parents('.skuSpecValueNames').index() - 1].id
                                });
                                addSelfCollectedGoodsTableListData[that.parents('tr').index()].specificationCode[that.parents('.skuSpecValueNames').index() - 1].productSpecValueList = newData2;


                            }
                            ;
                            form.render('select');
                            addSelfCollectedGoodsTbList.reload({data: addSelfCollectedGoodsTableListData})
                        });


                        form.on("select", function (data) {
                            if ($(data.elem).attr('name') == 'packId') {
                                addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].packId = {
                                    name: data.elem[data.elem.selectedIndex].text,
                                    value: data.value
                                }
                            } else if ($(data.elem).attr('name') == 'unitId') {
                                addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].unitId = {
                                    name: data.elem[data.elem.selectedIndex].text,
                                    value: data.value
                                }
                            } else if ($(data.elem).attr('class') == 'skuSpecValueNamesList') {
                                if (addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].skuSpecValueNames[$(data.elem).parents('.skuSpecValueNames').index() - 1] &&
                                    addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].skuSpecValueNames[$(data.elem).parents('.skuSpecValueNames').index() - 1].hasOwnProperty('parentId')) {
                                    addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].skuSpecValueNames[$(data.elem).parents('.skuSpecValueNames').index() - 1] = {
                                        name: data.elem[data.elem.selectedIndex].text,
                                        value: data.value,
                                        parentId: addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].skuSpecValueNames[$(data.elem).parents('.skuSpecValueNames').index() - 1].parentId
                                    };
                                } else {
                                    addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].skuSpecValueNames[$(data.elem).parents('.skuSpecValueNames').index() - 1] = {
                                        name: data.elem[data.elem.selectedIndex].text,
                                        value: data.value,
                                        // parentId : (parentId?parentId : void 1)
                                    };
                                }
                            } else if ($(data.elem).attr('name') == 'lifeUnit') {
                                addSelfCollectedGoodsTableListData[$(data.elem).parents('tr').index()].lifeUnit = {
                                    name: data.elem[data.elem.selectedIndex].text,
                                    value: data.value
                                }

                            }

                        });
                        // 工具条点击事件
                        table.on('tool(addSelfCollectedGoodsTableList)', function (obj) {
                            let data = obj.data;
                            // console.log(addSelfCollectedGoodsTableListData[obj.data.index])
                            if (obj.event === 'save') {
                                if (addSelfCollectedGoodsTableListData[obj.data.index].skuCode == '') {
                                    layer.msg('请输入物料编号', {icon: "5"});
                                    return false
                                } else if (addSelfCollectedGoodsTableListData[obj.data.index].skuName == '') {
                                    layer.msg('请输入物料规格名称', {icon: "5"});
                                    return false

                                } else if (addSelfCollectedGoodsTableListData[obj.data.index].oldSpecCode == '') {
                                    layer.msg('请输入旧规格码', {icon: "5"});
                                    return false

                                } else if (addSelfCollectedGoodsTableListData[obj.data.index].marketPrice == '') {
                                    layer.msg('请输入单价', {icon: "5"});
                                    return false

                                }
                                let newSkuCodeValue = [];
                                addSelfCollectedGoodsTableListData[obj.data.index].skuSpecValueNames.forEach(item => {
                                    if (item.parentId && item.text) {
                                        newSkuCodeValue.push({productSpecId: item.parentId, value: item.text})
                                    }
                                });
                                if (newSkuCodeValue.length > 0) {
                                    admin.req('enterprise/product/admin/productSpec/updateBatch', JSON.stringify(newSkuCodeValue), res => {
                                        if (res.code === 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            admin.reqSync('enterprise/product/admin/productSpec/getProductSpecByProductTypeId', {productTypeId: $('#addSelfCollectedGoodsProductTypeId').val()}, res => {
                                                if (res.code === 200) {
                                                    specificationCode = res.data;
                                                    addSelfCollectedGoodsTableListData.forEach(item => {
                                                        item.specificationCode = specificationCode.map(o => Object.assign({}, o));

                                                    });
                                                    addSelfCollectedGoodsTableListData[obj.data.index].skuSpecValueNames.forEach((item, index) => {
                                                        addSelfCollectedGoodsTableListData[obj.data.index].specificationCode[index].productSpecValueList.forEach(item1 => {
                                                            if (item.text == item1.value) {
                                                                addSelfCollectedGoodsTableListData[obj.data.index].skuSpecValueNames[index].value = item1.id;
                                                                addSelfCollectedGoodsTableListData[obj.data.index].skuSpecValueNames[index].parentId = void 0;
                                                            }
                                                        })
                                                    });

                                                    addSelfCollectedGoodsTableListData[obj.data.index].isShow = false;
                                                    addSelfCollectedGoodsTbList.reload({data: addSelfCollectedGoodsTableListData});
                                                }
                                            }, 'get');
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, 'POST', true, 'application/json; charset=utf-8');
                                } else {
                                    addSelfCollectedGoodsTableListData[obj.data.index].isShow = false;
                                    addSelfCollectedGoodsTbList.reload({data: addSelfCollectedGoodsTableListData});
                                }


                            } else if (obj.event === 'modify') {
                                addSelfCollectedGoodsTableListData[obj.data.index].isShow = true;
                                addSelfCollectedGoodsTbList.reload({data: addSelfCollectedGoodsTableListData});
                            }
                        });

                        form.on('submit(addSelfCollectedGoodsSubmit)', d => {
                            let row = $("[lay-id=addSelfCollectedGoodsTableList] table tbody tr");
                            let listData = [], listDataObj = {};
                            for (let i = 0; i < row.length; i++) {
                                if (row.eq(i).find("input[name='isShow']").val() == 'true') {
                                    continue;
                                }
                                let skuObj = {};
                                let skuCode = row.eq(i).find("input[name='skuCode']").val();
                                let skuName = row.eq(i).find("input[name='skuName']").val();
                                let oldSkuCode = row.eq(i).find("input[name='oldSkuCode']").val();
                                let oldSpecCode = row.eq(i).find("input[name='oldSpecCode']").val();
                                let skuString = '', skuSpecValueString = '', skuSpecString = '';
                                for (let j = 0; j < row.eq(i).find(".skuSpecValueNames").find('select').length; j++) {
                                    if (row.eq(i).find(".skuSpecValueNames").find('input').eq(j).val() == '') {
                                        skuString = '';
                                        skuSpecValueString = '';
                                        skuSpecString = '';
                                    } else {
                                        skuString += row.eq(i).find(".skuSpecValueNames").find('input').eq(j).val() + '-';
                                        skuSpecValueString += row.eq(i).find(".skuSpecValueNames").find('option:selected').eq(j).val() + '_';
                                        skuSpecString += row.eq(i).find(".skuSpecValueNames").find('option:selected').eq(j).attr('skuspec') + '_';
                                    }
                                }
                                let skuSpecValueNames = skuString.substring(0, skuString.length - 1);
                                let skuSpecValue = skuSpecValueString.substring(0, skuSpecValueString.length - 1);
                                let skuSpec = skuSpecString.substring(0, skuSpecString.length - 1);
                                let marketPrice = row.eq(i).find("input[name='marketPrice']").val();
                                let packId = row.eq(i).find("select[name='packId']").val();
                                let unitId = row.eq(i).find("select[name='unitId']").val();
                                let lifeUnit = row.eq(i).find("select[name='lifeUnit']").val();
                                let lifeSpan = row.eq(i).find("input[name='lifeSpan']").val();
                                skuObj = {
                                    skuCode: skuCode,
                                    skuName: skuName,
                                    oldSkuCode: oldSkuCode,
                                    oldSpecCode: oldSpecCode,
                                    skuSpecValueNames: skuSpecValueNames,
                                    marketPrice: marketPrice,
                                    skuSpecValue: skuSpecValue,
                                    packId: packId,
                                    unitId: unitId,
                                    skuSpec: skuSpec,
                                    lifeUnit: lifeUnit,
                                    lifeSpan: lifeSpan
                                };
                                listData.push(skuObj)
                            }


                            listDataObj.productDetailForm = listData;
                            listDataObj.productTypeId = d.field.addSelfCollectedGoodsProductTypeId;
                            listDataObj.productCategoryId = d.field.addSelfCollectedGoodsProductCategoryId;
                            listDataObj.brandId = d.field.addSelfCollectedGoodsBrandId;
                            listDataObj.name = d.field.name;
                            listDataObj.productCode = d.field.productCode;
                            listDataObj.picture = d.field.addSelfCollectedGoodsPicture;
                            if (listDataObj.productDetailForm.length <= 0) {
                                layer.msg('请添加或保存规格列表', {icon: 2});
                                return false
                            }
                            layer.load(2);
                            admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/addSelfPickProduct', JSON.stringify(listDataObj), res => {
                                layer.closeAll('loading');
                                if (res.code === 200) {
                                    layer.closeAll();
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('commonToolCabinetTable');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'POST', true, 'application/json; charset=utf-8')
                        });
                    }
                    form.render('select');
                }
            })
        }


        //加载  addSelfCollectedGoods 中的下拉框
        //addSelfCollectedGoods
        function loadAddSelfCollectedGoodsSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                }else if(type == 2){
                    html += `<option value='${data[i].id}'>${data[i].corporateName}</option>`;
                }
            }
            $("form.addSelfCollectedGoodsForm select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

        // 上传图片
        function uploadImg(_elem, pathId, inputId) {
            upload.render({
                elem: '#' + _elem
                , url: config.upload_url + 'uploadFile'
                , data: {}
                , accept: 'file'
                , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                , headers: {Authorization: 'Bearer ' + config.getToken()}
                , done: function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        let imagUrl = res.data.url;
                        $('#' + pathId).html('<img src="' + imagUrl + '"/>');
                        $('#' + inputId).val(imagUrl);
                    } else if (res.code == 502) {
                        return location.replace('admin/login.html');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            });
        }

        // 简版 添加物料
        function showAddProduct(data) {
            admin.open({
                type: 1,
                area: ['1280px', '600px'],
                offset: '65px',
                title: data ? '修改物料' : '添加物料',
                content: $('#compactProductForm').html(),
                success: function () {
                    if (data) {
                        data.unitId === 0 ? data.unitId = '' : '';
                        getProductUnitData(data.productTypeId);
                        getPackData(data.unitId);
                        // showInputTips(data.lifeUnitDesc)
                    }

                    // 选择包装方案
                    form.on('select(getPackId)', function (d) {
                        var marketPrice = $("input[name='marketPrice']").val();
                        var baseRate = "";
                        $("select[name='packId'] option").each(function (index, item) {
                            if(d.value != "" && d.value == $(item).val()){
                                baseRate = $(item).data("baserate");
                            }
                        })
                        calculateBasePrice(marketPrice, baseRate);
                    });

                    // 监听包装价格输入
                    $("input[name='marketPrice']").on("input",function(e){
                        var packId = $("select[name='packId']").val();
                        var baseRate = "";
                        $("select[name='packId'] option").each(function (index, item) {
                            if(packId != "" && packId == $(item).val()){
                                baseRate = $(item).data("baserate");
                            }
                        })
                        //获取input输入的值
                        var curValue = e.delegateTarget.value;
                        calculateBasePrice(curValue, baseRate);
                    });

                    // 设置基础单位单价
                    function calculateBasePrice(marketPrice, baseRate){
                        if(marketPrice && baseRate){
                            $("input[name='basePrice']").val((marketPrice/baseRate).toFixed(2));
                        }else{
                            $("input[name='basePrice']").val("");
                        }
                    }

                    // 获取规格系列
                    admin.req('enterprise/product/admin/productSeries/list', {limit:9999, type: 0, categoryType: "purchase", isDeleted: false}, function (res) {
                        if (res.code==200) {
                            loadShowAddProductSelectHtml(res.data, "请选择规格系列", "productId", 3);
                            form.on('select(getProduct)', function (d) {
                                if(d.value != ""){
                                    for (var i = 0; i < res.data.length; i++) {
                                        if(d.value == res.data[i].id){
                                            $("input[name='name']").val(res.data[i].name);
                                            $("input[name='productTypeId']").val(res.data[i].productTypeId);
                                            $("input[name='productTypeName']").val(res.data[i].productTypeName);
                                            $("input[name='productCategoryId']").val(res.data[i].productCategoryId);
                                            $("input[name='productCategoryName']").val(res.data[i].productCategoryName);
                                            $("input[name='skuSpecValueNames']").val(res.data[i].specCode);
                                            $('#compactProduct_path').html('<img src="' + res.data[i].picture + '" style="height: 50px;" />');
                                            $('#compactProductPicture').val(res.data[i].picture);
                                            getProductUnitData(res.data[i].productTypeId);
                                        }
                                    }
                                }else{
                                    $("input[name='name']").val("");
                                    $("input[name='productTypeId']").val("");
                                    $("input[name='productTypeName']").val("");
                                    $("input[name='productCategoryId']").val("");
                                    $("input[name='productCategoryName']").val("");
                                    $("input[name='skuSpecValueNames']").val("");
                                    $('#compactProduct_path').html("");
                                    $('#compactProductPicture').val("");
                                }
                                form.render();
                            })
                        } else {
                            layer.msg('获取规格系列失败', {icon: 2, time: 1000});
                        }
                    }, 'GET', false);

                    //查询企业信息
                    var enterpriseInfo;
                    admin.req('enterprise/system/admin/enterpricceId/getEnterpricceIdVO', {}, function (res) {
                        enterpriseInfo = res.data;
                    }, 'get', false);
                    if ("" == enterpriseInfo || null == enterpriseInfo) {
                        layer.msg("企业信息获取异常", {icon: 1});
                        return;
                    }

                    //请求单位数据
                    function getProductUnitData(_id) {
                        getPackData();
                        if (_id) {
                            admin.reqSync('enterprise/product/admin/productUnit/list', {
                                page: 1,
                                limit: 9999,
                                productType: _id
                            }, function (res) {
                                let list = []
                                res.data.forEach(item => {
                                    // 如果包装单位不是基础单位 并且没有被禁用
                                    if (!item.isBaseUnit && item.isDeleted) {
                                        list.push(item)
                                    }
                                })
                                loadShowAddProductSelectHtml(list, "请选择单位", "unitId", 1);
                            }, 'get');
                        } else {
                            loadShowAddProductSelectHtml([], "请选择单位", "unitId", 1);
                        }
                    }

                    // 请求包装方案
                    function getPackData(_id) {
                        if (_id) {
                            admin.reqSync('enterprise/product/admin/productPack/getByUnitId', {productUnitId: _id}, function (res) {
                                let packList = []
                                res.data.forEach(item => {
                                    if (item.isDeleted) {
                                        packList.push(item)
                                    }
                                })
                                loadShowAddProductSelectHtml(packList, "请选择包装方案", "packId", 4);
                            }, 'get');
                        } else {
                            loadShowAddProductSelectHtml([], "请选择包装方案", "packId", 4);
                        }
                    }

                    $("#productPackId").click(function () {
                        let val = $("select[name='unitId']").val()
                        if (val == null || val == '') {
                            layer.msg("请先选择单位", {icon: 2});
                        }
                    })

                    $("#selectUnitId").click(function () {
                        // let val = $("select[name='productTypeId']").val()
                        let val = $("input[name='productTypeId']").val();
                        if (val == null || val == '') {
                            layer.msg("请先选择物料类型", {icon: 2});
                        }
                    })

                    //加载物料类型
                    /*admin.reqSync('enterprise/product/admin/productType/getProductTypeByType', {type: 0}, function (res) {
                        let typeList = [];
                        res.data.forEach(item => {
                            // 如果没有被停用
                            if (item.isDeleted) {
                                typeList.push(item)
                            }
                        })
                        loadSelectHtml(typeList, "请选择物料类型", "productTypeId", "name");
                    }, 'get');*/

                    //加载供应商
                    // admin.reqSync('enterprise/purchase/admin/supplierInfoPass/getAll', {}, function (res) {
                    admin.reqSync('enterprise/purchase/admin/supplierInfoPass/getAll', {}, function (res) {
                        if (res.code === 200) {
                            loadShowAddProductSelectHtml(res.data, "请选择供应商", "supplierId", 2);
                        } else {
                            loadShowAddProductSelectHtml([], "请选择供应商", "supplierId", 2);
                        }
                    }, 'get');


                    form.on('select(compactProductTypeId)', function (d) {
                        getProductUnitData(d.value)
                    });

                    // form.on('select(lifeUnit)', function (d) {
                    //     let e = d.elem;
                    //     let text = e[e.selectedIndex].text;
                    //     if (!d.value) text = '';
                    //     showInputTips(text)
                    // });
                    /*function showInputTips(data){
                        $('form[lay-filter="compactProductForm"] .inputTipsText').text(data)
                    }*/
                    //单位下拉操作
                    form.on('select(compactUnitId)', function (d) {
                        getPackData(d.value)
                    });
                    //加载物料分类树级菜单
                    /*var arr2tree;
                    admin.reqSync('enterprise/product/admin/productCategory/getProductCategoryByType', {type: 0}, function (res) {
                        let categoryList = []
                        for (let i = 0; i < res.data.length; i++) {
                            if (res.data[i].isDeleted) {
                                res.data[i].children = [];
                                categoryList.push(res.data[i])
                            }
                        }
                        arr2tree = xmSelect.arr2tree(categoryList, "parentId", "id", "children", -1);
                    }, 'get');
                    var selectedData = function (treeData, targetId) {
                        for (var k = 0; k < treeData.length; k++) {
                            var nodeId = treeData[k].id;
                            if (targetId == nodeId) {
                                treeData[k].selected = true;
                                return;
                            } else {
                                if (treeData[k].children && treeData[k].children != '') {
                                    selectedData(treeData[k].children, targetId);
                                }
                            }
                        }
                    }
                    var smlSelectInstans = xmSelect.render({
                        el: '#compactProductCategoryId',
                        model: {label: {type: 'text'}},
                        radio: true,
                        clickClose: true,
                        filterable: true,
                        layVerify: 'required',
                        initValue: data ? [data.productCategoryId] : [],
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        tips: '顶级分类',
                        prop: {
                            name: 'name',
                            value: 'id',
                            children: 'children'
                        },
                        data() {
                            //填充数据
                            return arr2tree;
                        },
                        on(data) {
                            let parentId = data.arr.length > 0 ? data.change[0].id : -1;
                            $("input[name='productCategoryId']").val(parentId);
                        }
                    });*/
                    //加载品牌
                    admin.reqSync('enterprise/product/admin/productBrand/getAllProductBrandByType', {type: 0}, function (res) {
                        let brandList = []
                        res.data.forEach(item => {
                            if (item.isDeleted) {
                                brandList.push(item)
                            }
                        })
                        loadSelectHtml(brandList, "请选择品牌", "brandId", "name");
                    }, 'get');
                    if (data) {
                        $("#productName").val(data.productName);
                        data.returnType === true ? data.returnType = 'true' : data.returnType = 'false';
                        $('[lay-filter="compactProductForm"] input[name="skuCode"]').attr('disabled', 'disabled');
                        // selectedData(arr2tree, data.productCategoryId);
                        form.val('compactProductForm', data);
                    }

                    upload.render({
                        elem: '#compactProductUploadBtn'
                        , url: config.upload_url + 'uploadFile'
                        , data: {"path": enterpriseInfo.enterpriseCode + "/"}
                        , accept: 'file'
                        , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                        , headers: {Authorization: 'Bearer ' + config.getToken()}
                        , done: function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg || "上传成功", {icon: 1});
                                var imagUrl = res.data.url;
                                $('#compactProduct_path').html('<img src="' + imagUrl + '" style="height: 50px;" />');
                                $('#compactProductPicture').val(imagUrl);
                            } else if (res.code == 502) {
                                return location.replace('admin/login.html');
                            } else {
                                layer.msg(res.msg || "上传失败", {icon: 2});
                            }
                        }
                    });
                    if (data && data.productPic) {
                        $('#compactProduct_path').html('<img src="' + data.productPic + '" style="height: 50px;" />');
                        $('#compactProductPicture').val(data.productPic)
                    }
                    form.render('select');
                    // 表单提交事件
                    form.on('submit(compactProductFormSubmit)', function (d) {
                        // d.field.unitId === ''?d.field.unitId = 0:'';
                        layer.load(2);
                        admin.req(data ? 'enterprisecab/cabProduct/admin/mostUsedKnifeList/updateCompactProduct' : 'enterprisecab/cabProduct/admin/mostUsedKnifeList/addCompactProduct', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('commonToolCabinetTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        function loadShowAddProductSelectHtml(data, tips, htmltarget, type) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                } else if (type == 2) {
                    html += `<option value='${data[i].id}'>${data[i].corporateName}</option>`;
                } else if (type == 3) {
                    html += `<option value='${data[i].id}'>${data[i].name}(${data[i].specCode})</option>`;
                } else if (type == 4) {
                    html += `<option value='${data[i].id}' data-baserate='${data[i].baseRate}'>${data[i].name}</option>`;
                }
            }
            $("form[lay-filter='compactProductForm'] select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }


        // 模板下载（简版）
        $('#compactProductBtnTemplate').click(function () {
            window.location.href = config.base + "enterprisecab/productCab/admin/product/compactTemplate";
        });

        //导入excel（简版）
        $('#compactUploaderInput').on("change", function (e) {
            layer.load(2);
            var formData = new FormData();
            var files = e.target.files;
            let that = $(this);
            formData.append("file", files[0]);
            formData.append("name", files[0].name);//这个地方可以传递多个参数
            $.ajax({
                url: config.base + 'enterprisecab/productCab/admin/product/compactImportExcel',
                data: formData,
                headers: {Authorization: 'Bearer ' + config.getToken()},
                type: "POST",
                processData: false,
                contentType: false,
                success: function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('commonToolCabinetTable');
                        layer.closeAll('page');
                        setTimeout(_ => {
                            location.reload()
                        }, 1000);
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                    that.val('');
                }
            });
        })

        // 显示入库弹窗
        function showStorageModel(data) {
            console.log(data.data)
            admin.open({
                type: 1,
                area: ['420px', '400px'],
                offset: '165px',
                title: '入库',
                content: $('#storageForm').html(),
                success: function () {
                    form.val('storageForm', {
                        'skuCode': data.data.skuCode
                    });
                    form.verify({
                        integer: [
                            /^[1-9]\d*$/
                            , '只能输入正整数'
                        ]
                    });
                    //查询仓库
                    admin.req('enterprisecab/warehouse/admin/warehouse/getWarehouseVOAll', {}, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                $.each(res.data, function (index, item) {
                                    $("#warehouseIdOption").append(new Option(item.name, item.id));
                                })
                                form.render('select');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');
                    //查询包装方案
                    admin.req('enterprise/product/admin/productPack/list', {
                        limit: 999,
                        sort: 'id',
                        order: 'asc',
                        productType:data.data.productTypeId
                    }, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                var html = '';
                                for (var k = 0; k < res.data.length; k++) {
                                    html += '<option value="' + res.data[k].id + '" data-unitname="' + res.data[k].productUnitName + '" data-quantitypackunit="' + res.data[k].baseRate + '">' + res.data[k].name + '</option>'
                                }
                                $("#packId").html(html);
                                if(data.data.packId){
                                    $("#packId").val(data.data.packId);
                                    $("#packId").attr("disabled", "disabled");
                                }
                                form.render('select');

                                form.on('select(getPack)', function (d) {
                                    var quantity = $("input[name='quantity']").val();
                                    for (var i = 0; i < res.data.length; i++) {
                                        if(res.data[i].id == d.value){
                                            calculate(quantity, res.data[i].baseRate);
                                        }
                                    }
                                })
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');

                    $("input[name='quantity']").on("input",function(e){
                        var packId = $("select[name='packId']").val();
                        var baseRate = "";
                        $("select[name='packId'] option").each(function (index, item) {
                            if(packId != "" && packId == $(item).val()){
                                baseRate = $(item).data("quantitypackunit");
                            }
                        })

                        //获取input输入的值
                        var curValue = e.delegateTarget.value;
                        calculate(curValue, baseRate);
                    });

                    // 获取入库类型
                    admin.req('enterprisecab/warehouse/admin/warehouseInventoryType/list', {
                        limit: 999,
                        sort: 'id',
                        order: 'asc',
                        inventoryType: 'in',
                    }, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                var html = '';
                                for (var k = 0; k < res.data.length; k++) {
                                    html += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>'
                                }
                                $("#inType").html(html);
                                form.render('select');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');

                    // 表单提交事件
                    form.on('submit(storageFormSubmit)', function (d) {

                        layer.load(2);
                        d.field.inOutType = 'in';
                        d.field.quantityPackUnit = $("#packId" + " option:selected").data('quantitypackunit');
                        d.field.unitName = $("#packId" + " option:selected").data('unitname');
                        d.field.packName = $("#packId" + " option:selected").text();
                        admin.req('enterprise/order/admin/cabInventoryProduct/addCabInventoryProduct', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('commonToolCabinetTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }

        // 显示出库弹窗
        function showOutboundModel(data) {
            admin.open({
                type: 1,
                area: ['420px', '400px'],
                offset: '165px',
                title: '出库',
                content: $('#outboundForm').html(),
                success: function () {
                    form.val('outboundForm', {
                        'skuCode': data.data.skuCode
                    });
                    form.verify({
                        integer: [
                            /^[1-9]\d*$/
                            , '只能输入正整数'
                        ]
                    });
                    //查询仓库
                    admin.req('enterprisecab/warehouse/admin/warehouse/getWarehouseVOAll', {}, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                $.each(res.data, function (index, item) {
                                    $("#warehouseIdOption").append(new Option(item.name, item.id));
                                })
                                form.render('select');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');
                    //查询包装方案
                    admin.req('enterprise/product/admin/productPack/list', {
                        limit: 999,
                        sort: 'id',
                        order: 'asc',
                        productType:data.data.productTypeId
                    }, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                var html = '';
                                for (var k = 0; k < res.data.length; k++) {
                                    html += '<option value="' + res.data[k].id + '" data-unitname="' + res.data[k].productUnitName + '" data-quantitypackunit="' + res.data[k].baseRate + '">' + res.data[k].name + '</option>'
                                }
                                $("#packId").html(html);
                                if(data.data.packId){
                                    $("#packId").val(data.data.packId);
                                    $("#packId").attr("disabled", "disabled");
                                }
                                form.render('select');

                                form.on('select(getPack)', function (d) {
                                    var quantity = $("input[name='quantity']").val();
                                    for (var i = 0; i < res.data.length; i++) {
                                        if(res.data[i].id == d.value){
                                            calculate(quantity, res.data[i].baseRate);
                                        }
                                    }
                                })
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');

                    $("input[name='quantity']").on("input",function(e){
                        var packId = $("select[name='packId']").val();
                        var baseRate = "";
                        $("select[name='packId'] option").each(function (index, item) {
                            if(packId != "" && packId == $(item).val()){
                                baseRate = $(item).data("quantitypackunit");
                            }
                        })

                        //获取input输入的值
                        var curValue = e.delegateTarget.value;
                        calculate(curValue, baseRate);
                    });

                    // 获取出库类型
                    admin.req('enterprisecab/warehouse/admin/warehouseInventoryType/list', {
                        limit: 999,
                        sort: 'id',
                        order: 'asc',
                        inventoryType: 'out',
                    }, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                var html = '';
                                for (var k = 0; k < res.data.length; k++) {
                                    html += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>'
                                }
                                $("#outType").html(html);
                                form.render('select');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');

                    // 表单提交事件
                    form.on('submit(outboundFormSubmit)', function (d) {

                        layer.load(2);
                        d.field.inOutType = 'out';
                        d.field.quantityPackUnit = $("#packId" + " option:selected").data('quantitypackunit');
                        d.field.unitName = $("#packId" + " option:selected").data('unitname');
                        d.field.packName = $("#packId" + " option:selected").text();
                        admin.req('enterprise/order/admin/cabInventoryProduct/addCabInventoryProduct', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('commonToolCabinetTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }

        // 计算基础数
        function calculate(quantity, baseRate){
            $("input[name='quantityPack']").val(quantity*baseRate);
        }

        // 显示安全库存设置弹窗
        function showWarningModel(data) {
            admin.open({
                type: 1,
                area: ['360px', '180px'],
                offset: '165px',
                title: '安全库存设置',
                content: $('#warningForm').html(),
                success: function () {
                    form.val('warningForm', data.data);
                    // 表单提交事件
                    form.on('submit(warningFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req('enterprisecab/cabProduct/admin/mostUsedKnifeList/setSafetyInventory', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('commonToolCabinetTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }

        // 入库详情弹窗
        function showStorageDetailsModel(data) {
            admin.open({
                type: 1,
                area: "1500px",
                offset: '65px',
                title: '入库详情',
                content: $('#storageDetailForm').html(),
                success: function () {
                    var skuListTable2 = table.render({
                        elem: '#storageDetailTable',
                        url: config.base + 'order/admin/cabInventoryProductRecord/list?skuCode=' + data.skuCode,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'productName', title: '物料名称'}
                            , {field: 'skuCode', title: '物料编号'}
                            , {field: 'oldSpecCode', title: '规格码'}
                            , {field: 'quantity', title: '数量'}
                            , {field: 'warehouseName', title: '仓库'}
                            , {field: 'creatorName', title: '操作人'}
                            , {field: 'createTime', title: '入库时间'}
                        ]],
                    });
                }
            })
        }
    });
</script>